feat(nvim): add lazy loading for cmp

dev-docs
Moritz Böhme 2023-03-07 14:26:37 +01:00
parent 0556bfe81e
commit 2df38d379d
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
1 changed files with 56 additions and 51 deletions

View File

@ -48,59 +48,64 @@ require("nvim-treesitter.configs").setup({
}, },
}) })
local cmp = require("cmp") -- load cmp on InsertEnter
local luasnip = require("luasnip") vim.api.nvim_create_autocmd("InsertEnter", {
require("copilot_cmp").setup() callback = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
require("copilot_cmp").setup()
cmp.setup({ cmp.setup({
formatting = { formatting = {
format = require("lspkind").cmp_format({ format = require("lspkind").cmp_format({
mode = "symbol", -- show only symbol annotations mode = "symbol", -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters 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 ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
symbol_map = { symbol_map = {
Copilot = "", Copilot = "",
},
}),
}, },
}), snippet = {
}, -- REQUIRED - you must specify a snippet engine
snippet = { expand = function(args)
-- REQUIRED - you must specify a snippet engine require("luasnip").lsp_expand(args.body)
expand = function(args) end,
require("luasnip").lsp_expand(args.body) },
end, mapping = cmp.mapping.preset.insert({
}, ["<C-b>"] = cmp.mapping.scroll_docs(-4),
mapping = cmp.mapping.preset.insert({ ["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-b>"] = cmp.mapping.scroll_docs(-4), ["<C-Space>"] = cmp.mapping.complete(),
["<C-f>"] = cmp.mapping.scroll_docs(4), ["<C-e>"] = cmp.mapping.abort(),
["<C-Space>"] = cmp.mapping.complete(), ["<CR>"] = cmp.mapping.confirm({ select = true }),
["<C-e>"] = cmp.mapping.abort(), ["<Tab>"] = cmp.mapping(function(fallback)
["<CR>"] = cmp.mapping.confirm({ select = true }), if cmp.visible() then
["<Tab>"] = cmp.mapping(function(fallback) cmp.select_next_item()
if cmp.visible() then elseif luasnip.expand_or_jumpable() then
cmp.select_next_item() luasnip.expand_or_jump()
elseif luasnip.expand_or_jumpable() then else
luasnip.expand_or_jump() fallback()
else end
fallback() end, { "i", "s" }),
end ["<S-Tab>"] = cmp.mapping(function(fallback)
end, { "i", "s" }), if cmp.visible() then
["<S-Tab>"] = cmp.mapping(function(fallback) cmp.select_prev_item()
if cmp.visible() then elseif luasnip.jumpable(-1) then
cmp.select_prev_item() luasnip.jump(-1)
elseif luasnip.jumpable(-1) then else
luasnip.jump(-1) fallback()
else end
fallback() end, { "i", "s" }),
end }),
end, { "i", "s" }), sources = {
}), { name = "buffer", priority = 1 },
sources = { { name = "copilot", priority = 8 },
{ name = "buffer", priority = 1 }, { name = "luasnip", priority = 7 },
{ name = "copilot", priority = 8 }, { name = "nvim_lsp", priority = 9 },
{ name = "luasnip", priority = 7 }, { name = "orgmode", priority = 9 },
{ name = "nvim_lsp", priority = 9 }, },
{ name = "orgmode", priority = 9 }, })
}, end,
}) })
---merge tables ---merge tables