-
Notifications
You must be signed in to change notification settings - Fork 852
Real model for snippets #236
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
Comments
Where are these |
The docs for |
Search `$1` or `${` in protocol.md, it's a documentation on
`snippetSupport` flag.
|
The docs for InsertTextFormat as well as (redundantly) in the docs for
completion capabilities. The capability to handle snippets is one of the
'optional' features a client can implement
Although being optional, the way VSCode's language servers are implemented
makes it necessary for clients to declare support for snippets in the
ClientCapabilites, or completion is not available at all. So it's not that
optional for a client if consuming those LS is a goal ;)
|
Note that with my proposal, a server wouldn't really need to make the difference between snippet support or not: the edit only would already be valuable and usable (whereas snippets don't make it nice if not supported nowadays) and then clients could -optionally- implement the support for snippets/editGroups. |
Actually when we worked in the snippet support in VS Code we discussed such an approach. The reason why we decided against it is that creating the snippets is harder. If a character is added to the string you might need to adjust offset and length. This seemed to be very cumbersome. So you will either write code to help you with that or the client writes code to parse the snippet. We decided that overall it is better to ask the client to parse a string with a certain syntax (as other tools do as well). We took a subset of the text mate syntax so that client don't need to start from scratch. I agree that such a support would allow clients to easier provide snippet support since applied edits is easier than parsing strings. |
If a character is added to the string you might need to adjust offset and
length. This seemed to be very cumbersome.
I'm not sure I understand what you mean there. Can you please provide an
example?
The current state somehow requires to update offset and length and content
on both server and client side (to place the `$1` properly), so I'm not
sure it's less cumbersome.
I agree that such a support would allow clients to easier provide snippet
support since applied edits is easier than parsing strings.
And I have the impression it would also allow servers to easier provide
placeholders with suggestions and so on.
|
If I change the newText to `one$1 two${my variable name} three$1` |
When you say "I", you mean as a user of the tool or as the provider of the language server? If it's as a user of the tool, then I'd say it's up to the tool to keep consistent range according to user input. If it's a language server provider, I imagine there could be helpers to easilty turn a string with parameter capturing into a modeled text edit. |
To keep the number of issues in our inbox at a manageable level, we’re closing issues that have been on the backlog for a long time but haven’t gained traction: we look at the number of votes the issue has received and the number of duplicate issues filed. Thank you for your time and understanding. If you disagree and feel that this issue is crucial: we’re happy to listen and to reconsider. |
Currently, the snippets are defined with string conventions. That causes multiple issues:
$...
strings$
,{
or:
, it requires to escape those characters.I believe the protocol would be better at creating a model object for those tabstops. It would make things simpler to specify, adopt and maintain.
Here is a suggestion: allow those tabstops in text edit:
So instead of sending a TextEdit with newText=
one$1 two${2:foo} three$1
, LS would sendThen applying this becomes trivial: first apply the text, and then use the editGroups to put tabstops and so on.
Some additional benefits:
The text was updated successfully, but these errors were encountered: