When using LuaSnip together with nvim-cmp and a snippet library like friendly-snippets or luasnip-snippets you get a lot of duplicated snippets. That’s because the language server also servers snippets. Also, you might want to create your own custom snippet that happens to share the name of a snippet that already exists.
For example, with the setup mention above, let’s say that I also have a custom fn
snippet for Rust files. When I type fn
, nvim-cmp suggests three snippets: one from rust-analyzer, one from friendly-snippets and my custom one.
The solution to overriding friendly-snippets with your custom ones suggested in this open LuaSnip issue is to create your own fork of friendly-snippets. However, this is not ideal because it adds a lot of extra work to each user to ensure that their fork is up-to-date with upstream. Also, it doesn’t solve the issue with language servers serving snippets with the same name. I know that for most language servers you can disable snippets, but that doesn’t really solve the issue either because you might want some of those snippets.
What I would like is the option to only see one of the snippets listed if there are multiple ones with the same name. Which one would be controlled with a priority list, for example:
- If there’s a custom user snippet, use that
- Otherwise, if there’s an LSP snippet, use that
- Otherwise, use the one from friendly-snippets
Is this possible to achieve today?
does the
dup
completion-item option work for that? it should at least dedup items from the same source, which should work as it’s all the luasnip source(?)https://github.com/hrsh7th/nvim-cmp/issues/511
https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L534
https://neovim.io/doc/user/insert.html#complete-functionsit matters in what order the items are loaded in with this: the first one wins