t0vim/lua/custom/completion.lua

65 lines
1.5 KiB
Lua

-- Set some settings for competion
-- For more info type `:help completeopt`
-- menu: Show menu when completions available (more than 1)
-- menuone: Show menu even when there is only 1 option
-- noselect: Force user to select convinient option
-- Load luasnip setup
require "custom.luasnip"
vim.opt.completeopt = { "menu", "menuone", "noselect" }
local lspkind = require "lspkind"
local kind_formatter = lspkind.cmp_format {
mode = "symbol_text",
menu = {
buffer = "[buf]",
nvim_lsp = "[LSP]",
nvim_lua = "[api]",
path = "[path]",
luasnip = "[snip]",
gh_issues = "[issues]",
tn = "[TabNine]",
eruby = "[erb]",
},
}
local cmp = require "cmp"
cmp.setup {
sources = {
{ name = "luasnip" },
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "buffer" },
},
mapping = {
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
["<C-y>"] = cmp.mapping(
cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
},
{ "i", "c" }
),
},
-- Enable luasnip to handle snippet expansion for nvim-cmp
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
formatting = {
fields = { "abbr", "kind", "menu" },
expandable_indicator = true,
format = function(entry, vim_item)
-- Lspkind setup for icons
vim_item = kind_formatter(entry, vim_item)
return vim_item
end,
},
}