44 lines
1.2 KiB
Lua
44 lines
1.2 KiB
Lua
--- Ensure plugins are installed
|
|
local ok, cmp, luasnip, lspkind = pcall(function()
|
|
return require("cmp"), require("luasnip"), require("lspkind")
|
|
end)
|
|
|
|
if not ok then
|
|
return
|
|
end
|
|
|
|
--- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
|
|
|
local opts = {
|
|
completion = {
|
|
completeopt = "menu,menuone,preview,noselect",
|
|
},
|
|
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
|
|
["<C-e>"] = cmp.mapping.abort(), -- close completion window
|
|
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
|
}),
|
|
-- sources for autocompletion
|
|
sources = cmp.config.sources({
|
|
{ name = "nvim_lsp" },
|
|
{ name = "luasnip" }, -- snippets
|
|
{ name = "buffer" }, -- text within current buffer
|
|
{ name = "path" }, -- file system paths
|
|
}),
|
|
-- configure lspkind for vs-code like pictograms in completion menu
|
|
formatting = {
|
|
format = lspkind.cmp_format({
|
|
maxwidth = 50,
|
|
ellipsis_char = "...",
|
|
}),
|
|
},
|
|
}
|
|
|
|
cmp.setup(opts)
|