Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add programmatically selected snippet #33280

Closed
augb opened this issue Aug 28, 2017 · 4 comments
Closed

Add programmatically selected snippet #33280

augb opened this issue Aug 28, 2017 · 4 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code) snippets

Comments

@augb
Copy link

augb commented Aug 28, 2017

See this Stack Overflow question for more details.

  • VSCode Version: 1.15.1
  • OS Version: Win 10 Pro (64 bit)

I am able to invoke editor.action.insertSnippet programmatically; however, I would like to not require the user to select a snippet. Instead, I want to add a button that will invoke a predefined snippet on behalf of the user. Something along the lines of editor.action.insertSelectedSnippet.

@vscodebot vscodebot bot added editor editor-multicursor Editor multiple cursor issues labels Aug 28, 2017
@rebornix rebornix assigned jrieken and unassigned rebornix Sep 5, 2017
@jrieken
Copy link
Member

jrieken commented Sep 6, 2017

The insertSnippet-command accepts an argument which is either the name of a snippet or a snippet itself. So, either { snippet: "console.log($1)$0"} for an inline snippet or { langId: "csharp", name: "myFavSnippet" } referencing an existing snippet.

@jrieken jrieken closed this as completed Sep 6, 2017
@jrieken jrieken added *question Issue represents a question, should be posted to StackOverflow (VS Code) snippets and removed editor editor-multicursor Editor multiple cursor issues labels Sep 6, 2017
@augb
Copy link
Author

augb commented Sep 6, 2017

This seems to be exactly what I need. Thank you.

@augb
Copy link
Author

augb commented Sep 6, 2017

@jrieken Having had a few moments to review the docs (insertSnippet, SnippetString and full snippet syntax), I am not seeing this referenced (at least not as clearly as you did in reply). Would it be possible to update the documentation to be more explicit about this?

@jrieken
Copy link
Member

jrieken commented Sep 6, 2017

Yeah, it is well-hidden in the snippets sections: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_assign-keybindings-to-snippets

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code) snippets
Projects
None yet
Development

No branches or pull requests

3 participants