ipatalas / vscode-postfix-ts

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

Custom templates don't show up in the autocomplete menu #32

Closed aaronmcadam closed 4 years ago

aaronmcadam commented 4 years ago

Here's my custom template:

"postfix.customTemplates": [
    {
      "name": "dl",
      "description": "detailed log",
      "body": "console.log('{{expr}}', {{expr}});$0",
      "when": [
        "expression"
      ]
    }
  ]

See this screen capture:

CleanShot 2020-02-12 at 11 24 49

ipatalas commented 4 years ago

Hi, first of all thanks for a very good bug report. I wish all of them were that descriptive :)

Ok, I see two potential problems here.

One is that app. is not an expression but just an identifier type of context. That's all described here in details. If that's not self explanatory, let me know, I'll try to rephrase.

Having that in mind you should update the config as follows:

"postfix.customTemplates": [
    {
      "name": "dl",
      "description": "detailed log",
      "body": "console.log('{{expr}}', {{expr}});$0",
      "when": [
        "expression",
        "identifier"
      ]
    }
  ]

expression will still be handy for object.property.value or array[index] code.

The other, less obvious issue is that while trying to repro the problem I have found out that only workspace configuration is taken into account so if this sits in your user settings.json then it won't work. As a workaround just place it into workspace settings.json. I will fix that in next release.

Update: ok, it's slightly different. When postfix.customTemplates are provided in both user and workspace settings then workspace setting shadows user setting. Settings with the same key are not merged - apparently that's how VSCode works. If you only have it one place everything should be fine. Let me know if that helps.

aaronmcadam commented 4 years ago

Thanks so much @ipatalas, it works now by adding support for identifiers. While the docs are good, I think it might be useful to show some example custom templates to help people learn.