Dynamic snippet evaluation in VSCode

前端 未结 2 1522
余生分开走
余生分开走 2021-01-11 23:32

Is it possible for a snippet to insert a dynamically computed completion or snippet in Visual Studio Code?

I would like a snippet for inserting date and time strings

2条回答
  •  北海茫月
    2021-01-11 23:56

    It's definitely not possible to execute a script or something similar within a snippet.

    You can write an extension for Visual Studio Code instead. The extension must implement a CompletionItemProvider.

    Its provideCompletionItems method would return a list of CompletionItems. Their filterText properties would be set to the texts displayed in the suggestion box (for example "date" or "time") and their insertText properties would be set to the dynamically computed values.

    Finally you would need to register the completion provider using registerCompletionItemProvider.

    You should absolutely take a look on how to create an extension before you start: https://code.visualstudio.com/docs/extensions/example-hello-world

提交回复
热议问题