85 lines
2.3 KiB
Lua
85 lines
2.3 KiB
Lua
local cmp = require("cmp")
|
|
local luasnip = require("luasnip")
|
|
local lspkind = require("lspkind")
|
|
require("luasnip/loaders/from_vscode").lazy_load()
|
|
|
|
cmp.setup({
|
|
completion = {
|
|
completeopt = "menu,menuone,preview,noselect",
|
|
},
|
|
window = { -- making ui stuff for completion bordered
|
|
completion = cmp.config.window.bordered(),
|
|
documentation = cmp.config.window.bordered(),
|
|
},
|
|
-- configure lspkind for vs-code like pictograms in completion menu
|
|
formatting = {
|
|
format = lspkind.cmp_format({
|
|
maxwidth = 50,
|
|
ellipsis_char = "...",
|
|
}),
|
|
},
|
|
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = {
|
|
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
|
|
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
|
|
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
|
|
["<C-y>"] = cmp.config.disable,
|
|
["<C-c>"] = cmp.mapping({ -- close completion window
|
|
i = cmp.mapping.abort(),
|
|
c = cmp.mapping.close(),
|
|
}),
|
|
["<CR>"] = cmp.mapping.confirm({
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = false,
|
|
}),
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
elseif luasnip.expandable() then
|
|
luasnip.expand()
|
|
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
|
|
luasnip.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
},
|
|
cmp.setup.cmdline(":", {
|
|
mapping = cmp.mapping.preset.cmdline(),
|
|
sources = {
|
|
{ name = "cmdline" },
|
|
},
|
|
}),
|
|
-- cmp.setup.cmdline("/", {
|
|
-- mapping = cmp.mapping.preset.cmdline(),
|
|
-- sources = {
|
|
-- { name = "buffer" },
|
|
-- },
|
|
-- }),
|
|
-- sources for autocompletion
|
|
sources = {
|
|
{ name = "nvim_lsp" },
|
|
{ name = "nvim_lsp_signature_help" }, -- parameter hints
|
|
{ name = "luasnip" }, -- snippets
|
|
{ name = "buffer" }, -- text within current buffer
|
|
{ name = "path" }, -- file system paths
|
|
{ name = "codeium" }, -- AI for autocompletion
|
|
-- { name = "calc" }, --for maths calculations
|
|
},
|
|
})
|