-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Ability to insert dynamically generated snippets through extensions #3210
Comments
@shardulm94 Unsure if it works but you explore adding a completion item provider that returns completions of kind Snippet. With that you should get support for placeholders |
Whoa, interesting. So if a completion is of type |
go for it @daviwil |
@jrieken I tried this today. But it inserts the tabstops and placeholders as text itself. |
the syntax is like so: |
@jrieken Great, thanks! This fits my needs! EDIT: It would be really helpful if you could point me to where this syntax is documented. |
unsure. @alexandrudima will know |
We didn't document it because we didn't want it to spread. @jrieken maybe completions coming from the extension host should go through https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.ts#L226 such that we don't end up documenting and making API of our internal format. |
This would be a huge step for https://github.com/joelday/vscode-docthis. (I still haven't figured out a way to change the selection position to inside the range of new edits.) Hope to see this get formalized as an external API. |
Stretch for August, likely Sept |
Looking forward to this |
We have basically two options for this, an easy and a complicated option. Option A (and that is the easy one) is that we simply document our internal snippet format and build on it in the future. It has the advantage of not requiring new API to signal this completion string uses snippet syntax and should be handled special because already today it is like that. The obvious disadvantage is that we introduce another syntax in addition to the TM snippet syntax. Option B would be to build on the TM snippet syntax and it would mean that we need a flag/type to signal this string is a TM snippet such that we don't break existing completion providers. It would also require us to reach more parity with the actual TM snippet syntax and it would raise the question if the existing, implicit, behaviour should be turned off. Suggestions welcome! |
I think, if it helps, just do away with the whole textmate syntax for snippets. VSCode anyways supports only a limited subset of the snippets, writing/converting the existing tmSnippets to JSON is painful, and there are bugs even in that, such as tabs not properly jumping to the next snippet, tabs jumping to first snippet after the last one, etc, which make the snippets part a very weak part of the software. If there is a better way, why not use that? This new optionA although sounds good, will create more fragmentation in the way snippets are written/maintained IMO. |
Just having a look at this on insiders build. Is there any sample code on this new API can work? |
Cheers. I just downloaded the insiders build but I can't seem to be able That typescript example is not quite what I want I believe. I would like On 19 November 2016 at 15:29, Danny Tuppeny [email protected]
|
(Note: I haven't updated to this yet, so I might be talking gibberish!)
Di you need to update the vscode
I'm not really sure what's different from what this does and what you want. There was undocumented functionality that allowed completion providers to have placeholders that the user could tab between (we use in Dart Code to pre-fill arguments) which is why this is a fairly small change for those already using that. If you weren't previously using it then there's probably additional work to get your snippets in via a completion provider. |
We are done with this. Please try out things and report feedback |
@jchannon Re #3210 (comment) When programming against insiders you need the latest and greatest |
Yeah. I added 1.8.0 for engine version and its seemed to download the d.ts but On 22 November 2016 at 10:01, Johannes Rieken [email protected]
|
Yeah - you might update your project/extension to run with TypeScript 2.0. See: http://code.visualstudio.com/updates/v1_6#_extension-authoring |
I have: "engines": { "devDependencies": { But get no intellisense when typing vscode. On 22 November 2016 at 12:44, Johannes Rieken [email protected]
|
i have it working, had to compile ts files for some reason then vscode On 23 November 2016 at 09:18, Jonathan Channon [email protected]
|
Yeah, |
👍 👍 👍 |
Hi guys, great to have this feature allowing to use snippets from CompletionItems. However I can't make it work in my case. I want the completion to insert something before the text being completed. I know I can do that using additionalTextEdits but I also want this part to be an editable snippet. The basic PoC code is as follows: let range = new vsc.Range(position.translate(0, -1), position)
let item = new vsc.CompletionItem('var', vsc.CompletionItemKind.Snippet)
item.insertText = `var {{name}} = `
item.range = range Unfortunately such completion item isn't even shown in the dropdown list. What I was able to figure is that it's related to the new range field. VS Code version: |
@ipatalas A few things: (1) Then about |
@jrieken thanks for a very quick answer Regarding the snippet syntax, I know. I've been just trying them all with no success and this one I ended up with so I took this example somehow by accident. Thanks for the note about Cheers, |
Currently, you can only insert a string from an extension using
TextEditorEdit
. I am in the process of creating a jsdoc comments extension, and it can insert TextMate-style snippets, but only as a string. It would be much better if one could iterate through all the placeholders rather than manually moving the cursor.The effect would be similar to the one in the
Function Documentation
section hereWould it be possible to get a feature like this?
The text was updated successfully, but these errors were encountered: