emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.75k stars 869 forks source link

Does tsserver client support snippet insertion? #3337

Open titaniumbones opened 2 years ago

titaniumbones commented 2 years ago

Is your feature related or already mentioned on the wishlist?

I couldn't find it.

Describe your feature here.

I'm not sure if this is a bug, a feature request, or a confusion on my part. I'm am trying to get some of the features I like from VSCode. In particular, I'd like to have keyword expansion trigger snippet insertion in the buffer. I think this should be possible, but I'm not seeing the same set of options in my completion popup as I see in VSCode, and choosing the function completion only completes the word, rather than filling in a snippet template. Hopefully the images below help to explain the issue.

I think I'm using the same language server that VSCode uses -- mine is tsserver 0.9.5, from what I can tell vscode uses the same one.

Any hints? Thanks! Screenshot from 2022-02-02 09-23-50 (company completion, lsp-completion-provider set to :capf)

Screenshot from 2022-02-02 09-16-40 (corfu completion, lsp-completion-provider set to :none)

Screenshot from 2022-02-02 09-15-20 (VSCode completion options; note the icon in front of the Function statement option appears to be different in the Emacs backends)

Screenshot from 2022-02-02 09-15-40 (VSCode snippet insertion)

yyoncho commented 2 years ago

Do you have yasnippet installed and enabled? In general completion snippets work when they are provided by the server. Also, you can group yasnippet company backend with lsp-mode's one and you will get client-side snippets

titaniumbones commented 2 years ago

hmm. I'm sorry to be a little dense. Is there a reference backed that I should test out to be sure the issue isn't with my javascript server? Here's what I've tried just now:

in my main emacs, execute lsp-plain. In the new emacs, execute the following in scratch:

(package-install 'yasnippet-snippets)
(require 'company-yasnippet)
(setq company-backends '((company-capf company-yasnippet)))
(setq lsp-completion-provider :capf) ; ;I'm not sure if this is still recommende

in a pristine directory, create a new file test.js and register the workspace with .

in the buffer, type function.

I am not seeing a snippet option in the company popup.

Does it seem like I'm doing something wrong here?

yyoncho commented 2 years ago

If you want to do it like this you can change that to setq-local and use lsp-managed-mode-hook.

(setq company-backends '((company-capf company-yasnippet)))