-
Notifications
You must be signed in to change notification settings - Fork 95
Suggest filters compatible with the object type #669
Conversation
8d68b90
to
409cb05
Compare
lib/theme_check/language_server/completion_providers/filter_completion_provider.rb
Outdated
Show resolved
Hide resolved
lib/theme_check/language_server/completion_providers/filter_completion_provider.rb
Outdated
Show resolved
Hide resolved
test/language_server/completion_providers/filter_completion_provider_test.rb
Outdated
Show resolved
Hide resolved
test/language_server/completion_providers/filter_completion_provider_test.rb
Outdated
Show resolved
Hide resolved
test/language_server/completion_providers/filter_completion_provider_test.rb
Outdated
Show resolved
Hide resolved
test/language_server/completion_providers/filter_completion_provider_test.rb
Outdated
Show resolved
Hide resolved
assignment levels
lib/theme_check/language_server/completion_providers/filter_completion_provider.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice 🔥 added some non blocking comments and will approve after tophatting on thursday
lib/theme_check/language_server/completion_providers/filter_completion_provider.rb
Outdated
Show resolved
Hide resolved
lib/theme_check/language_server/completion_providers/filter_completion_provider.rb
Outdated
Show resolved
Hide resolved
available_labels | ||
.select { |w| w.start_with?(partial(content, cursor)) } | ||
context = context_with_cursor_before_potential_filter_separator(context) | ||
available_filters_for(determine_input_type(context)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that I initially .map
ped over all filters to get all .name
from filters, just to pass every label to the ShopifyLiquid::Documentation.filter_doc
method, which .find
s each filter again 🤦🏻♂️ 🤣
Has been fixed now, so that filter_to_completion
gets the complete filter, with nice information like deprecated?
partial_match[1] | ||
end | ||
|
||
def filter_to_completion(filter) | ||
content = ShopifyLiquid::Documentation.filter_doc(filter) | ||
content = ShopifyLiquid::Documentation.render_doc(filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally decided not to group the filters, and outsourced this question to https://github.com/Shopify/theme-check/issues/675
Unfortunately yes – I did not change the logic, the deprecated filters are just more prominent now 😢: "deprecated": true,
"syntax": "variable | article_img_url",
"name": "article_img_url" Therefore, these filters – no matter if they are deprecated or not – are suggested for every type. Among 9 start = { 'variable' => [0, 0], 'string' => [0, 0], 'form' => [0, 0], 'font' => [0, 0],
'number' => [0, 0], 'array' => [0, 0], 'media' => [0, 0], 'metafield' => [0, 0], 'paginate' => [0, 0], 'address' => [0, 0], 'type' => [0, 0] }
ShopifyLiquid::SourceIndex.filters.each_with_object(start) do |filter, result|
result[filter.input_type][filter.deprecated? ? 1 : 0] += 1
end
=> {"variable"=>[5, 4], "string"=>[82, 2], "form"=>[2, 1], "font"=>[3, 0], "number"=>[17, 0], "array"=>[11, 0], "media"=>[4, 0], "metafield"=>[2, 0], "paginate"=>[1, 0], "address"=>[1, 0], "type"=>[2, 0]} Possible solutions
|
goooot it thanks for the explanation! i think if you havent already lets capture this in an issue as a possible enhancement. for now tho i think it's a good idea to keep it as is, we can get feedback from developers what we release and see if it's confusing. but i suspect hiding the deprecated suggestion all together will be more frustrating
sorting deprecated variable suggestions to the bottom might also be a good compromise 😮 |
→ #676 – Done :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 🚀 🚀
* 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]>
WHY are these changes introduced?
Fixes #658
WHAT is this pull request doing?
FilterCompletionProvider
to…| default
)How to test your changes?
For all cases (if not stated differently):
array
string
number
form
font
media
metafield
paginate
address
Display all filters
In the following examples, return types have no corresponding filter (e.g.
article.image
has return typeimage
, but there is no filter forimage |
). Therefore, make sure that all filters are suggested.Display deprecated filters
Verify that deprecated filters are crossed out, and that a deprecation reason is shown.
