panoply / vscode-liquid

💧Liquid language support for VS Code
https://marketplace.visualstudio.com/items?itemName=sissel.shopify-liquid
Other
171 stars 23 forks source link

Weird indentation when formatting a "render" or "include" #185

Closed christian10xinnovation closed 4 months ago

christian10xinnovation commented 5 months ago

Hey everyone, New here and this is my first issue post :) Been struggling to get the indentation of these lines of code right. Not sure if this is my own fault or if it's an issue. Anyway, maybe someone can help, thanks in advance! Before: image After: image

panoply commented 5 months ago

Hey @christian10xinnovation

So this is rule related and it works in a 2 iteration cycle, meaning If you were to hit cmd + s a second time (or rerun the formatting command) it will restructure itself to position the comma , characters to be placed before the parameters, for example:

Before

{% render 'product-image', 
   param_1: object.prop1, 
   param_2: object.foo
%}

After

{% render 'product-image'
  , param_1: object.prop1
  , param_2: object.foo
%}

If you prefer comma character to be place after parameter expressions as per your screenshot, You can adjust the position placement of comma characters using the Liquid lineBreakSeparator formatting rule. You can change that setting in either your .liquidrc file or your workspace settings:

If you are using a .liquidrc file you can adjust the formatting setting as follows:

{
   "format": {
     "liquid": {
        "lineBreakSeparator": "after" // set this to after
     }
  }
}

If you are using Workspace settings, you can adjust the formatting setting as follows:

{
   "liquid.format.rules": {
      "liquid": {
        "lineBreakSeparator": "after" // set this to after
      }
   }
}

You can find information for the formatting rule in the Æsthetic documentation here: https://aesthetic.js.org/rules/liquid/lineBreakSeparator/

christian10xinnovation commented 5 months ago

Awesome, this is exactly what I was looking for. Didn't find the documentation before (probably not looked hard enough), so thanks a lot for linking it and thanks for developing this extension!