feat(nvim): add luasnip snippets
This commit is contained in:
parent
659e719c47
commit
e87d0c7ec3
5 changed files with 260 additions and 43 deletions
|
|
@ -2,23 +2,12 @@ local cmp = require("cmp")
|
|||
local luasnip = require("luasnip")
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
local has_words_before = function()
|
||||
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
|
||||
return false
|
||||
end
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
|
||||
end
|
||||
|
||||
cmp.setup({
|
||||
formatting = {
|
||||
format = require("lspkind").cmp_format({
|
||||
mode = "symbol", -- show only symbol annotations
|
||||
maxwidth = 50, -- prevent the popup from showing more than provided characters
|
||||
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
|
||||
symbol_map = {
|
||||
Copilot = "",
|
||||
},
|
||||
}),
|
||||
},
|
||||
snippet = {
|
||||
|
|
@ -31,36 +20,55 @@ cmp.setup({
|
|||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<S-CR>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() and has_words_before() then
|
||||
if luasnip.jumpable(1) then
|
||||
luasnip.jump(1)
|
||||
elseif cmp.visible() then
|
||||
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
if luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
elseif cmp.visible() then
|
||||
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<C-n>"] = cmp.mapping(function(fallback)
|
||||
if luasnip.choice_active() then
|
||||
luasnip.change_choice(1)
|
||||
elseif cmp.visible() then
|
||||
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<C-p>"] = cmp.mapping(function(fallback)
|
||||
if luasnip.choice_active() then
|
||||
luasnip.change_choice(-1)
|
||||
elseif cmp.visible() then
|
||||
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
sources = {
|
||||
sources = cmp.config.sources({
|
||||
{ name = "async_path", priority = 1 },
|
||||
{ name = "buffer", priority = 1 },
|
||||
{ name = "spell", priority = 1 },
|
||||
{ name = "luasnip", priority = 2 },
|
||||
{ name = "copilot", priority = 3 },
|
||||
{ name = "nvim_lsp", priority = 3 },
|
||||
{ name = "nvim_lsp", priority = 2 },
|
||||
{ name = "nvim_lsp_signature_help", priority = 3 },
|
||||
},
|
||||
{ name = "luasnip", priority = 4 },
|
||||
}, {
|
||||
{ name = "async_path" },
|
||||
{ name = "buffer" },
|
||||
{ name = "spell" },
|
||||
}),
|
||||
})
|
||||
|
||||
-- Set configuration for specific filetype.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue