Open andrewbranch opened 3 years ago
Does the protocol currently have a way to express "this completion item is a snippet" so that the icon can be changed? Maybe it's implied by the presence of a cursor marker?
Sounds like the right approach to me then.
Notes from editor meeting:
CompletionEntry
.
VS Code ships with an extension called
typescript-basics
which contains static snippet definitions for things like control flow constructs and basic declarations. When TS Server serves a request for completions, it includes a boolean switch that controls whether these snippets are added to the completion items in its response, but it can’t say which ones are relevant for the requesting location—it’s all or nothing. This leads to a pretty poor UX, like offering a for-loop in the body of a class:But we can’t disable that without disabling the useful method declaration snippet:
But equally embarrassingly, the method declaration snippets are offered outside of classes as well:
Now that TS Server has native support for generating snippets, we can easily do better. The simplest change would be to copy these snippets from
typescript-basics
into TS Server and let TS Server include only the relevant ones in a given response. (I say “copy” and not “move” so as not to change the behavior for JS/TS users who have completely disabled TS Server, or during times when TS Server is not available.) Another approach could be to let TS Server’s completions response include some sort of filtering information instead of an all-or-nothing switch to mix the snippets in from the typescript-basics source, but this sounds more complicated, more error-prone, and less backward compatible to me—but in general I’m open to other ways of solving the same problem.