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

59 lines
1.3 KiB
Lua
Raw Normal View History

2021-02-23 11:27:32 +00:00
-------------------------------------------------------------------------------
-- - LSP completion config -
-------------------------------------------------------------------------------
-- Set completeopt to have a better completion experience
2021-10-08 14:28:07 +00:00
vim.o.completeopt = "menu,menuone,noselect"
2021-03-23 10:54:28 +00:00
2022-04-28 13:53:54 +00:00
local cmp = require("cmp")
2022-04-27 21:43:49 +00:00
local luasnip = require("luasnip")
2022-04-28 13:53:54 +00:00
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" },
},
})