Shopify / theme-tools

Everything developer experience for Shopify themes
https://shopify.dev/docs/themes
MIT License
68 stars 19 forks source link

Lint, highlight and complete snippet signatures #211

Open charlespwd opened 10 months ago

charlespwd commented 10 months ago

Is your feature request related to a problem? Please describe. A new look at https://github.com/Shopify/theme-tools/issues/448

When you type {% render 'snippet', arg1: some_value %}, we don't check that that snippet needs that arg1 variable, nor do we do reliably report UndefinedObject in the snippet.

Describe the solution you'd like I'd like something that helps folks on both ends.

Describe alternatives you've considered

bertiful commented 6 months ago

👋🏻 there's a second part to this that would be extremely helpful for theme developers; checking what values for params are available.

While knowing if a param of type {String} is fine, knowing what string values can be passed is even better. Something like:

{%- comment -%}
  Some kind of snippet that outputs an image of different sizes

  @param {Object} image - Image object
  @param {'33'|'50'|'66'} media_width - Width of the media
{%- endcomment -%}

The syntax here is based on JSDoc's specification for type unions. Not sure if the formatting is the most optimal in a Liquid context, but it's an idea.

There are also other things we can check for. For example, auto-completion of {Boolean} values should populate and check for true/false values, and should result in an error for anything other than these two values. I'm sure there are things we can do with the {Object}that will further help with the developer experience as well.

charlespwd commented 6 months ago

Yeah I think https://github.com/Shopify/theme-tools/issues/114 wants to address just that. Hard to prioritize right now but definitely still something on our radar :)

PhoneDroid commented 4 months ago

Some thoughts on the matter:

@Keyword <Parameter> { <Type } <Description>

Valid syntax examples: ( I chose 'input' as the keyword )

{%- liquid

    #
    # @With { String } Message for something or other
    # @input Flavor { 'Vanilla' , 'Chocolate' }
    # @Input isTasty {Boolean} Is it tasty?
    # @INPUT   IS-EXTREME   {   Boolean }      EXTREME PARAMETERS
    # @Input Multiline_Description { String } 
    #        Describes a parameter on multiple
    #        lines, where every next line
    #        that isn't empty, not a comment
    #        or another declaration is part of it.
    #

-%}

{% comment %}

    @Ouput Something you have been waiting for.

{% endcomment %}

Wrote this on my phone, now my fingers hurt~ [ Edit ] Added some more later on