Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Introduce the ObjectAttributeCompletionProvider module #654

Merged
merged 14 commits into from
Nov 28, 2022

Conversation

karreiro
Copy link
Contributor

@karreiro karreiro commented Nov 7, 2022

Overview

The goal of this PR is fixing #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

  • 52029b5 - Now, we create the variable_lookup_finder/constants module to hold some regexes (they will be used in the future commits)
  • 753ce9a - 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
  • 6b45882 - After that, we introduce the AssignmentsFinder module
  • e27f9df - 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

  • 13b3751 - 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

  • da2c38f - 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

  • fc749d3 & a324fb3 - 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 #642 issue. But, I've decided to break that concept into sub-components into this PR to clarify what each phase means.

@karreiro karreiro marked this pull request as ready for review November 8, 2022 10:34
Copy link
Contributor

@mgmanzella mgmanzella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolute 🔥!! only question i have is the same one CP raised here

Copy link
Contributor

@Poitrin Poitrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, I just found some stuff during tophatting :)

implement `completions(context)` instead of `completions(relative_path, line, col)`
to DRY IO calls
Copy link
Contributor

@mgmanzella mgmanzella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀 🚀

karreiro and others added 2 commits November 22, 2022 17:08
  - Introduce scope support the in the `AssignmentsFinder`
    with the `TolerantParser`
  - Introduce support to variables defined in iteration statements
  - Fix documentation format
* Add file at desired location

* Read data from JSON file

* Update built_in_liquid_objects.json
Copy link
Contributor

@charlespwd charlespwd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :) 🔥 🔥 🔥

  - Use a single instance of `CompletionContext` on all providers
  - Remove variable from all parent scopes when it is defined in a block
  - Extra visitor and node handler from `AssignmentsFinder`
  - Remove `index!` in favor of an alternative
  - Introduce documentation for `TolerantBlockBody`
  - Rename `ObjectAttributeCompletionProvider#property_doc` to `[...]#property_to_completion`
@karreiro karreiro merged commit a5feea0 into language-server-docs-main Nov 28, 2022
mgmanzella added a commit that referenced this pull request Dec 9, 2022
* Define the domain for the `theme-liquid-docs` files (#643)

* Introduce the `ObjectAttributeCompletionProvider` module (#654)

* Download theme-liquid-docs on package deploy or while running theme-check (#661)

* Download theme-liquid-docs on package deploy

* Add data fixtures to test downloading theme-liquid-docs

* Introduce the `AssignmentsCompletionProvider` to suggest variables (#667)

* Refresh theme-liquid-docs on theme-check startup (#671)

* Add async download in SourceManager#refresh and mechanism to notify SourceIndex liquid schema is out of date

* Tests for SourceIndex state classes and SourceManager#refresh, create helper for shared stubs

* Cleanup -- fix test dir name to source_index, aggr requires

* Remove class method mock (Net::HTTP.any_instance), affects other tests

* Change SourceIndex#local_path to #local_path! to indicate danger, fix syntax of filename const

* Suggest filters compatible with the object type (#669)

### WHY are these changes introduced?

Fixes #658

### WHAT is this pull request doing?

1. Adds logic to `FilterCompletionProvider` to…
- determine the type of the variable/literal (string, number, array, …) sitting before the filter separator ("input type")
- suggest filters that match the specific input type, and filters whose input type is _variable_ (i.e. for more than 1 specific type, e.g. ` | default`)

2. Displays deprecated filters too, so that users can still see the filter they wanted to use.

Co-authored-by: Morisa Manzella <[email protected]>
Co-authored-by: Julien Poitrin <[email protected]>
Co-authored-by: Julien Poitrin <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants