Open DustinCampbell opened 8 years ago
@DustinCampbell There are snippets and completions. The former are static and it would be hard to add dynamic command arguments to it.
However, a completion provider can return a completion of type snippet
and we plan to enhance things in August such that completion can have a onDidAccet
-command and additional text edits (#6874). The main difference there is the prefix, like cw
, ctor
etc. You can still react to those, but maybe its wise to also the same amount of luxury for more regular completions
@jrieken, if a completion provider returns completions of type snippet
does those still populate the new Insert Snippet command?
No and I unsure if we should. The change is easy but we cannot make the same change to the tabCompletion feature - since we need to know sync' if a prefix matches. That would make both features different. This needs some thinking... Maybe some sort of special snippet provider that must statically announce its snippets (at least prefix and title) and is then pinged to make the actual insert.
Yeah, I'm not sure if it should either, but I'd also hate to have a disjoint snippet experience where, say, the ctor
snippet works from the completion list, but not via tab completion or insert snippet.
@DustinCampbell How this item stack against #6874? Same, more/less important, exclusive?
check - #6874 will land soon
We could do something like textmate interpolated shell code but for vscode commands. For instance a snippet would look like this
constructor `commandThatReturnsCtorName`(`commandThatReturnsCtorArgs`) {
$1
}
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 snippet
That'd be way cool
@DustinCampbell Would you mind me closing this as a duplicate of https://github.com/Microsoft/vscode/issues/3210? The idea is to advocate the use of CompletionItemProvider
returning SnippetStrings
instead of smart but static snippets.
The problem with the latter is that they are still static ;-) For instance, you won't be able to say don't propose the ctor snippet inside method-bodies etc, etc. Implementing a completion item provider that returns snippet-completion would allow you all those cool things
Is the plan to integrate those into the Insert Snippet command? Or, would the list that appears in that command be different from those that can appear in completion?
Yeah, we could do that. Harder than that is to integrate this with the tab-completion feature...
Will that happen too? I just want to be sure that users have a consistent experience. Wouldn't it be weird if some snippets work with tab completion, but others only work when completion is triggered?
Would love to see this in the June release.
I'd love to be able to use this. As a use case, I've got C++ include guards which would be better off if they used the file name (through $TM_FILENAME
) but can't since I'd have to replace dots in the filename with underscores.
use CompletionItem
to provide a snippet
is hard to set details
, any way to render the snippet with some locals programify, so we could set it to details.
Any updates on inserting current timestamp/datetime for code snippet ?
@DollarAkshay It's worth it to read the release notes ;) https://code.visualstudio.com/updates/v1_20#_more-snippet-variables
Hi,
I want to create a snippet that will give me <tag uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" class="className">
on type of "tag" and the uuid has to generated on expansion of the snippet.
I did get the insert guid snippet but it inserts the snippet through command palette but I want the snippet to be inserted on type of "tag".
Is there a way to do this?
Being able to run vscode commands in the backticks would also be really useful.
Hi,
I want to create a snippet that will give me <tag uuid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" class="className">
on type of "tag" and the uuid has to generated on expansion of the snippet.
I did get the insert guid snippet but it inserts the snippet through command palette but I want the snippet to be inserted on type of "tag".
Is there a way to do this?
@jrieken What's the chance of texmate code-execution-in-backticks being added any time soon?
I'd like to perform several regex substitutions in a snippet, and I can't see any other way.
So... if I type ctor
and get public 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.
Is there any update on this task?
Reading through the numerous linked issues it's not clear to me what status this issue is in regards to the backlog? It has a reasonable amount of support and keen users.
How does this get transitioned to a milestone goal?
I would add that having a way to define our own variables available in all snippets in a code-snippets
file would help.
Related on Stack Overflow: How to define and use custom variable for VS Code snippets
Also a use-case in vscode snippet variables: how to get content from output of command line program
Is this the feature that would allow this use case: https://github.com/microsoft/vscode-discussions/discussions/1274?
Can VSC extensions still not extend the list of snippet variables?
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?