ipatalas / vscode-postfix-ts

Postfix notation for TypeScript/Javascript - extension for VS Code
MIT License
158 stars 43 forks source link

Can i pass the body of custom template as array of string type? #115

Closed eenaree closed 1 year ago

eenaree commented 1 year ago

When creating templates with many rows in the body, using newline characters like '\n' and '\t' can make the template look messy and less visually appealing.

"postfix.customTemplates": [
    {
      "name": "class extends",
      "body": "class ${1:{{expr:capitalize}}Extended} extends {{expr:capitalize}} {\n\tconstructor($2) {\n\t\tsuper($3)$0\n\t}\n}\n",
      "description": "extends Class Declaration",
      "when": ["identifier"]
    }
]

Instead of using string, can i pass the body of custom template as array of string type, like vscode's snippets?

for example,

{
  "body": [
    "class ${1:{{expr:capitalize}}Extended} extends {{expr:capitalize}} {",
    "  constructor($2) {",
    "    super($3)$0",
    "  }",
    "",
  ]
}
ipatalas commented 1 year ago

Well, I never thought of that but it's a great idea! Also very simple to implement - took me 5-10 minutes to get it working. A new version (1.13.1) has been just released with that change. You can now either pass it as single string or array of strings. I had to leave single string option for backward compatibility. Enjoy!

eenaree commented 1 year ago

Thanks for listening to my thoughts. Depending on the complexity of the template, I think we can select the type of value to pass. Thanks again!