.dotfiles/.config/nvim/lua/nvwynd/plugins/completion.lua

72 lines
1.7 KiB
Lua
Raw Normal View History

2024-05-24 16:07:28 +03:00
return {
{
"hrsh7th/nvim-cmp",
lazy = false,
priority = 100,
dependencies = {
"onsails/lspkind.nvim",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
"hrsh7th/cmp-buffer",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
opts = function(_, opts)
opts.sources = opts.sources or {}
table.insert(opts.sources, {
name = "lazydev",
group_index = 0,
})
end,
2024-05-24 16:07:28 +03:00
config = function()
vim.opt.completeopt = { "menu", "menuone", "noselect" }
-- some nice cmp icons
local lspkind = require("lspkind")
lspkind.init({})
local cmp = require("cmp")
cmp.setup({
mapping = cmp.mapping.preset.insert({
-- `Enter` key to confirm completion
["<CR>"] = cmp.mapping.confirm({ select = false }),
-- `Esc` key to close the menu
["<ESC>"] = cmp.mapping.abort(),
-- Ctrl+Space to trigger completion menu
["<C-Space>"] = cmp.mapping.complete(),
-- Scroll up and down in the completion documentation
-- ["<S-q>"] = cmp.mapping.scroll_docs(-4),
-- ["<S-a>"] = cmp.mapping.scroll_docs(4),
}),
sources = cmp.config.sources({
{
name = "nvim_lsp",
entry_filter = function(entry, ctx)
-- 1 is the Text entry from LSP specs
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind
if entry:get_kind() == 1 then
return false
end
return true
end,
},
{ name = "path" },
-- { name = "buffer" },
}),
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
formatting = {
format = lspkind.cmp_format({}),
},
})
end,
},
}