2023-08-24 19:39:11 +02:00
|
|
|
return {
|
|
|
|
"hrsh7th/nvim-cmp",
|
|
|
|
event = "InsertEnter",
|
|
|
|
dependencies = {
|
|
|
|
"hrsh7th/cmp-buffer", -- source for text in buffer
|
|
|
|
"hrsh7th/cmp-path", -- source for file system paths
|
2024-04-03 17:08:26 +02:00
|
|
|
{
|
|
|
|
"L3MON4D3/LuaSnip",
|
|
|
|
-- follow latest release.
|
|
|
|
version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
|
|
|
-- install jsregexp (optional!).
|
|
|
|
build = "make install_jsregexp",
|
|
|
|
},
|
2023-08-24 19:39:11 +02:00
|
|
|
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
|
|
|
"rafamadriz/friendly-snippets", -- useful snippets
|
2023-09-02 03:40:47 +02:00
|
|
|
"onsails/lspkind.nvim", -- vs-code like pictograms
|
2023-08-24 19:39:11 +02:00
|
|
|
},
|
|
|
|
config = function()
|
|
|
|
local cmp = require("cmp")
|
2022-10-17 20:40:36 +02:00
|
|
|
|
2023-08-24 19:39:11 +02:00
|
|
|
local luasnip = require("luasnip")
|
2022-10-17 20:40:36 +02:00
|
|
|
|
2023-08-24 19:39:11 +02:00
|
|
|
local lspkind = require("lspkind")
|
2022-10-17 20:40:36 +02:00
|
|
|
|
2023-09-02 03:40:47 +02:00
|
|
|
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
2023-08-24 19:39:11 +02:00
|
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
2022-10-17 20:40:36 +02:00
|
|
|
|
2023-08-24 19:39:11 +02:00
|
|
|
cmp.setup({
|
2023-09-02 03:40:47 +02:00
|
|
|
completion = {
|
|
|
|
completeopt = "menu,menuone,preview,noselect",
|
|
|
|
},
|
|
|
|
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
2023-08-24 19:39:11 +02:00
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert({
|
|
|
|
["<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-e>"] = cmp.mapping.abort(), -- close completion window
|
|
|
|
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
2024-12-10 14:51:40 +01:00
|
|
|
["<Tab>"] = cmp.mapping(function(fallback) -- next part of snippet
|
|
|
|
if luasnip.expandable() then
|
|
|
|
luasnip.expand()
|
|
|
|
elseif luasnip.locally_jumpable(1) then
|
|
|
|
luasnip.jump(1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }), -- in both insert and select mode
|
|
|
|
["<S-Tab>"] = cmp.mapping(function(fallback) -- previous part of snippet
|
|
|
|
if luasnip.locally_jumpable(-1) then
|
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { "i", "s" }), -- in both insert and select mode
|
2023-08-24 19:39:11 +02:00
|
|
|
}),
|
|
|
|
-- sources for autocompletion
|
|
|
|
sources = cmp.config.sources({
|
2024-04-03 17:08:26 +02:00
|
|
|
{ name = "nvim_lsp"},
|
2023-08-24 19:39:11 +02:00
|
|
|
{ name = "luasnip" }, -- snippets
|
|
|
|
{ name = "buffer" }, -- text within current buffer
|
|
|
|
{ name = "path" }, -- file system paths
|
|
|
|
}),
|
2024-04-03 17:08:26 +02:00
|
|
|
|
2023-09-02 03:40:47 +02:00
|
|
|
-- configure lspkind for vs-code like pictograms in completion menu
|
2023-08-24 19:39:11 +02:00
|
|
|
formatting = {
|
|
|
|
format = lspkind.cmp_format({
|
|
|
|
maxwidth = 50,
|
|
|
|
ellipsis_char = "...",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}
|