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

Suggest filters compatible with the object type #669

Merged
merged 12 commits into from
Dec 9, 2022

Conversation

Poitrin
Copy link
Contributor

@Poitrin Poitrin commented Nov 25, 2022

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)
  1. Displays deprecated filters too, so that users can still see the filter they wanted to use.

How to test your changes?

For all cases (if not stated differently):

  • Make sure that filters for only the current input type are suggested.
  • Verify that filters for variable input types are always suggested.

array

{% assign ct = current_tags | 
{% assign c = product.collections | 
{{ current_tags | 
{{ product.collections | 

{% assign ct = current_tags %}
{{ ct | 

{{ blog.metafields | 

string

{% assign t = product.title | 
{{ page_description | 

{% assign t = product.title %}
{{ t | 

{{ 'test%40test.com' | 
{{ '' | 

{% for tag in collection.all_tags %}
  {%- if current_tags contains tag -%}
    {{ tag | 

{{ product.selected_variant.url | 

{%- assign collection_product = collection.products.first -%}
{{ collection_product.url | 

{% assign secret_potion = 'Polyjuice' | 

{%- assign text = '  Some potions create whitespace.      ' -%}
{{ text | 

number

{{ cart.total_price | 

{% assign tp = cart.total_price %}
{{ tp | 

{{ -4.2 | 

form

{{ form | 

font

{{ font.variants.first | 

media

{{ product.featured_media | 

{% for media in product.media %}
  {% if media.media_type == 'external_video' %}
    {% if media.host == 'youtube' %}
      {{ media | 

metafield

{{ shop.metafields | 

paginate

{{- paginate | 

address

{{ shop.address | 

Display all filters

In the following examples, return types have no corresponding filter (e.g. article.image has return type image, but there is no filter for image | ). Therefore, make sure that all filters are suggested.

{{ article.image | 
{{ product.metafields.information.seasonal | 
{{ product | 
{{ settings.type_header_font | 
{{ false | 

{%- assign display_price = false -%}
{{ display_price | 

Display deprecated filters

{{ 'foo.js' | hex_to
{% assign t = product.title | 

Verify that deprecated filters are crossed out, and that a deprecation reason is shown.
deprecation

@Poitrin Poitrin changed the base branch from fix-642 to fix-659 November 25, 2022 13:57
Base automatically changed from fix-659 to language-server-docs-main December 2, 2022 08:14
@Poitrin Poitrin force-pushed the fix-658 branch 2 times, most recently from 8d68b90 to 409cb05 Compare December 2, 2022 16:03
@Poitrin Poitrin requested review from mgmanzella and a team and removed request for karreiro December 7, 2022 19:18
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.

very nice 🔥 added some non blocking comments and will approve after tophatting on thursday

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))
Copy link
Contributor Author

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 .mapped over all filters to get all .name from filters, just to pass every label to the ShopifyLiquid::Documentation.filter_doc method, which .finds 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)
Copy link
Contributor Author

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

@Poitrin Poitrin requested a review from mgmanzella December 8, 2022 16:44
@mgmanzella
Copy link
Contributor

should i be seeing these deprecated filters for integers and other object types?

Screenshot 2022-12-08 at 12 25 09 PM

Screenshot 2022-12-08 at 12 23 02 PM

@Poitrin
Copy link
Contributor Author

Poitrin commented Dec 9, 2022

should i be seeing these deprecated filters for integers and other object types?

Unfortunately yes – I did not change the logic, the deprecated filters are just more prominent now 😢:
If I take article_img_url as an example, you will see that its input type is variable:

  "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 variable filters, 4 are deprecated (which are the ones you see in your screenshots).

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

  1. (my fav) We update the docs so that the 4 aforementioned deprecated filters get the input type image instead. That way, they are only suggested when working with images like article.image.
  2. We hide all deprecated filters. (Or at least deprecated variable filters.)

@mgmanzella
Copy link
Contributor

mgmanzella commented Dec 9, 2022

Unfortunately yes – I did not change the logic, the deprecated filters are just more prominent now 😢:

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

Possible solutions
(my fav) We update the docs so that the 4 aforementioned deprecated filters get the input type image instead. That way, they are only suggested when working with images like article.image.
We hide all deprecated filters. (Or at least deprecated variable filters.)

sorting deprecated variable suggestions to the bottom might also be a good compromise 😮

@Poitrin
Copy link
Contributor Author

Poitrin commented Dec 9, 2022

if you havent already lets capture this in an issue as a possible enhancement

#676Done :-)

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.

🚀 🚀 🚀

@Poitrin Poitrin merged commit 5921642 into language-server-docs-main Dec 9, 2022
@Poitrin Poitrin deleted the fix-658 branch December 9, 2022 15:38
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.

[Intelligent code completion] Suggest filters compatible with the object type
3 participants