How to prefer luasnip over lsp ? #361
Answered
by
VonHeikemen
lotusirous
asked this question in
Q&A
-
I would like to have the luasnip selected before lsp recommendation. Do we have any method to achieve this behavior ? Here is the following config local cmp = require("cmp")
local cmp_action = require("lsp-zero.cmp").action()
local cmp_format = require("lsp-zero").cmp_format()
local cmp_select_opts = { behavior = cmp.SelectBehavior.Select }
cmp.setup({
formatting = cmp_format,
sources = {
{ name = "path" },
{ name = "nvim_lsp" },
{ name = "buffer", keyword_length = 3 },
{ name = "luasnip", keyword_length = 2 },
{ name = "nvim_lsp_signature_help" },
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
["<C-k>"] = cmp.mapping.confirm({ select = true }),
["<C-e>"] = cmp.mapping.abort(),
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-f>"] = cmp_action.luasnip_jump_forward(),
["<C-l>"] = function()
local ls = require("luasnip")
if ls.choice_active() then
ls.change_choice(1)
end
end,
["<C-b>"] = cmp_action.luasnip_jump_backward(),
["<Up>"] = cmp.mapping.select_prev_item(cmp_select_opts),
["<Down>"] = cmp.mapping.select_next_item(cmp_select_opts),
["<C-p>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item(cmp_select_opts)
else
cmp.complete()
end
end),
["<CR>"] = function(fallback)
if cmp.visible() then
cmp.mapping.confirm({ select = true })(fallback)
else
return fallback()
end
end,
},
}) Where the luasnip is lazy loading from vscode
|
Beta Was this translation helpful? Give feedback.
Answered by
VonHeikemen
Dec 24, 2023
Replies: 1 comment 1 reply
-
The easiest way I can think of is moving the sources = {
{ name = "path" },
{ name = "luasnip"},
{ name = "nvim_lsp" },
{ name = "buffer", keyword_length = 3 },
{ name = "nvim_lsp_signature_help" },
}, My personal preference is to have different sources = {
{ name = "path" },
{ name = "nvim_lsp", keyword_length = 3 },
{ name = "buffer", keyword_length = 3 },
{ name = "luasnip", keyword_length = 2 },
{ name = "nvim_lsp_signature_help" },
}, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lotusirous
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The easiest way I can think of is moving the
luasnip
source abovenvim_lsp
. That will change the "priority" of the completion items.My personal preference is to have different
keyword_length
. Soluasnip
suggestions will appear on 2 keystrokes, and the lsp appear after 3 keystrokes. But I still keep the lsp with higher priority.