reddit / emacs

lsp-mode completions w/ snippets ? in JavaScript esp.

titaniumbones · 2022-02-02 15:06
I've been using lsp-mode a little bit, but not a ton, and 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! [vscode completions](https://preview.redd.it/l30dcls9qff81.png?width=1287&format=png&auto=webp&s=320ae9c6a6f99ca82697019f8a057a5cbc43ec83) ​ [vscode snippet insertion](https://preview.redd.it/8xx9am7cqff81.png?width=473&format=png&auto=webp&s=9756bbe296e99e4ba0707be48b8ad677a0271a0a) ​ [corfu insertion](https://preview.redd.it/wa0sanmdqff81.png?width=508&format=png&auto=webp&s=55c5ef555a48b08ae4d38d82f4bdb075b5d06439) [company completion](https://preview.redd.it/ltrixxg7qff81.png?width=521&format=png&auto=webp&s=d58ceb85577aaf673ed5713b77ec9cb1fc8301ad)
[deleted] · 2022-02-02 17:28
[deleted]
titaniumbones · 2022-02-02 18:03
hmm. \`yas-minor-mode\` is on, though I've now tried disabling it. It doesn't work in either case.
whale-sibling · 2022-02-02 19:06
does `company-backends` contain `company-yasnippet`? `(add-to-list 'company-backends company-yasnippet)` What happens if you run `M-x yas-expand`? Are these snippets part of LSP? I'm not completely familiar with it.
thepalmcivet · 2022-02-02 22:20
Granted you are using `company-mode` and have `yasnippet` installed and enabled, try setting `(setq lsp-completion-provider :none)`. I got tripped up on this a few months ago as well. Here's the backstory: https://github.com/emacs-lsp/lsp-mode/issues/3173
titaniumbones · 2022-02-02 23:22
well, I'm not certain. I know that in python and css mode I do get some template-y expansions, which is great. I think something about the javascript server interaction isn't quite right but I I can't tell. I know that the server has snippet-provision capacity, but I don't understand lsp enough to know how snippets are supposed to be managed. I wouldn't think that yasnippet or company-yasnippet would be required.
titaniumbones · 2022-02-02 23:24
hmm, I've tried botth :none and :capf and had no luck so far :-( I think the issue is with the :exit-function property of \`lsp-completion-at-point\` but it's a bit over my head when I look at the code.
hvis · 2022-02-03 02:52
You don't need `company-yasnippet` if the LSP server provides its own snippets with completions. I'm not sure whether it's the case, though. Perhaps the `function` snippet in VS Code is not coming from the language server?
hvis · 2022-02-03 02:52
You still need `yasnippet`, to work as the UI for snippet expansion.
titaniumbones · 2022-02-03 04:46
thanks for answering, I appreciate it. I guess yasnippet is invoked by lsp, hmm. I'm trying to figure out what configuration I need to make this work. Is it something like this: **with company** ``` (setq lsp-completion-provider :capf) (yas-minor-mode 1) (company-mode 1) (corfu-mode -1) (add-to-list 'company-backends 'company-yasnippet) (lsp) ``` **with corfu** ``` (setq lsp-completion-provider :none) (yas-minor-mode 1) (corfu-mode 1) (company-mode -1) (lsp) ``` It looks to me like something complicated is happening in `lsp-completion-exit-fn`, but there's some sophisticated usage of dash.el and I can't quite understnad it. i do know that in javascript I am unable to get `text-exit?` within `lsp-completion--exit-fn` to evaluate as non-nil, and I don't know why that would be, as it seems like the server itself supports snippets and has one for `function` in particular. So, honestly, I odn't really get it.
hvis · 2022-02-03 12:19
Perhaps u/yyoncho has some suggestion?
hvis · 2022-02-03 22:20
If no answer come here, I recommend you use one of lsp-mode's support channels: Discussions, Issues, or Discord.