dotfiles/symlinks/config/nvim/lua/esensar/lsp/completion.lua

63 lines
1.4 KiB
Lua

-------------------------------------------------------------------------------
-- - LSP completion config -
-------------------------------------------------------------------------------
-- Set completeopt to have a better completion experience
vim.o.completeopt = "menu,menuone,noselect"
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
["<C-n>"] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
["<C-p>"] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
["<C-j>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" }),
["<C-k>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = "nvim_lsp" },
{ name = "nvim_lua" },
{ name = "path" },
{ name = "luasnip" },
{ name = "buffer" },
},
})
cmp.setup.filetype("ledger", {
sources = cmp.config.sources({ name = "omni" }),
})