Execute functions during snippet expansion
See original GitHub issue- VSCode Version: 1.4
- OS Version: any
There are several snippets that exist in Visual Studio today that I would like to introduce to the C# extension for VS Code, but require generating dynamic text are executing code to perform other actions during snippet expansion. For example:
ctor
– generate a constructor declaration, automatically filling in the name of the constructor with the enclosing type name.testclass
– generate a test class and adds references to necessary test assemblies.cw
– generateSystem.Console.WriteLine()
but simplify the type name with the current using directives. So,System.
is removed ifusing System;
is in scope.
From what I can tell, snippets only support text with placeholders today. Is it possible to generate text dynamically or execute commands with arguments during snippet expansion?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:44
- Comments:26 (15 by maintainers)
Top Results From Across the Web
Execute function in vscode snippet - Stack Overflow
Is it possible to run a function during expansion of snippet? javascript.json - vscode snippet file: function add() { return 2 ...
Read more >Code Snippet Functions - Visual Studio (Windows)
There are three functions available to use with C# code snippets. Functions are specified in the Function element of the code snippet.
Read more >Snippets in Visual Studio Code
Snippets in Visual Studio Code. Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements....
Read more >Expanding snippets
You can use YASnippet to expand snippets in different ways: When yas-minor-mode is active: Type the snippet's trigger key then calling yas-expand (bound...
Read more >Run function after specific snippet - Emacs Stack Exchange
If the snippet worked, then there will be text in the region. We expect the snippet to either work or fail gracefully, not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We could do something like textmate interpolated shell code but for vscode commands. For instance a snippet would look like this
When inserting such a snippet we identify the command references and replace them with whatever their execution returned (
executeCommand
). As arguments we could pass the document, position, and snippetSo… if I type
ctor
and getpublic ClassName(Parameters)
… That’s still the expected behavior, if not perhaps the desired behavior?From the two threads I’ve skimmed, seems the requested feature has not been implemented yet? I thought it was my VSCode editor performing sub-optimally, but now I think I’m just wishing for a feature others requested three years ago.