I recommend reviewing this PR by following the sections below. I've split it into meaningful commits to approach each module individually and clarify its purpose.
Steps to review
1. Minor adjustments
c8c7f3c7e5e13d7df67d611a96fc992b3f17b6b - First of all, we slightly adjust a detail in the Markdown documentation
911c53a9ae792a0cb748c97e6b63b160d60e2c8 - Then, we introduce the prototype implementation to support built-in types
52029b5bf134edb612c5028494fb66123d2f829 - Now, we create the variable_lookup_finder/constants module to hold some regexes (they will be used in the future commits)
753ce9a30a05064377b7167dadf6dd10048c817 - Then, we introduce the main module of the type inference, the LiquidFixer
It receives a Liquid string and tries to turn it in a valid/parsable Liquid string
This module is designed to receive unfinished snippets, as while developers are typing, templates will be probably broken
6b458821b1e24f6a954e54a1d806a69e44e1209 - After that, we introduce the AssignmentsFinder module
This module relies on a Liquid visitor to get all assign occurrences
e27f9dfaa43f85042acffd21e57531a1c09948b - With those elements in place, we can now change the VariableLookupFinder to use the AssignmentsFinder and the LiquidFixer modules
With them, the VariableLookupFinder can follow variables and get their types based on assignments
3. Improve our code completion suggestions
13b37515a63f2f5c922f39ded6c7fafb848dd8b - Cool! We have our new mechanism in place; it's time to use it to provide valuable suggestions
But, before that, we need to apply some minor changes
The CompletionEngine works as an aggregator of all completion providers (each completion provider extends CompletionProvider)
With that in mind, we're changing the CompletionProvider main method from completions(content, cursor) to completions(relative_path, line, col)
The goal of this change is empowering each provider to suggest completion items based on the file, the line, and the column (instead of content, which was the current token a subset of the file)
Good! We're done with that
Now, let's update the existing completion providers and introduce documentation on them as well (as we have it for free now) :)
4. The new ObjectAttributeCompletionProvider provider
da2c38fe51ca3ecfb474a95a74752aa06c115e8 - Ok, in the latest commits, we updated the existing completion providers, it's time to introduce the new 'ObjectAttributeCompletionProvider' provider
Our new provider relies in the new VariableLookupFinder implementation to provide intelligent code completion for attributes
Now, we're pretty much done
5. TODO
fc749d3db443166a055e71e605ff7f3585b0d5b8 & a324fb326570b60601b78537b73f6bf2eaa34ca9 - These commits just introduce some references about the pending work we have
Steps to 🎩
Setup your editor (VS Code, vim, or nvim) with your local Theme Check by following this guide
Create a new theme with shopify theme init
Open your new theme to try code completion
Notice that filters/tags/objects code completion items have documentation now
Notice that objects support multi-level attribute code completion now:
* I've been calling the features introduced by this PR as "type inference" in https://github.com/Shopify/theme-check/issues/642 issue. But, I've decided to break that concept into sub-components into this PR to clarify what each phase means.
Overview
The goal of this PR is fixing https://github.com/Shopify/theme-check/issues/642* and introducing new intelligent code completion capabilities on Theme Check.
I recommend reviewing this PR by following the sections below. I've split it into meaningful commits to approach each module individually and clarify its purpose.
Steps to review
1. Minor adjustments
2. Setup our new code completion tools
variable_lookup_finder/constants
module to hold some regexes (they will be used in the future commits)LiquidFixer
AssignmentsFinder
moduleassign
occurrencesVariableLookupFinder
to use theAssignmentsFinder
and theLiquidFixer
modulesVariableLookupFinder
can follow variables and get their types based on assignments3. Improve our code completion suggestions
CompletionEngine
works as an aggregator of all completion providers (each completion provider extendsCompletionProvider
)CompletionProvider
main method fromcompletions(content, cursor)
tocompletions(relative_path, line, col)
content
, which wasthe current tokena subset of the file)4. The new
ObjectAttributeCompletionProvider
providerVariableLookupFinder
implementation to provide intelligent code completion for attributes5. TODO
Steps to 🎩
shopify theme init
* I've been calling the features introduced by this PR as "type inference" in https://github.com/Shopify/theme-check/issues/642 issue. But, I've decided to break that concept into sub-components into this PR to clarify what each phase means.