.dotfiles/configs/nvim/lua/autocomplete.lua

52 lines
1.5 KiB
Lua
Raw Normal View History

2021-09-06 13:29:42 +02:00
-- luasnip setup
2021-09-24 12:47:15 +02:00
local luasnip = require "luasnip"
2021-09-06 13:29:42 +02:00
2021-09-24 12:47:15 +02:00
local cmp = require "cmp"
2021-09-06 13:29:42 +02:00
cmp.setup {
2021-09-24 12:47:15 +02:00
completion = {
completeopt = "menu,menuone,noselect"
},
preselect = "none",
2021-09-06 13:29:42 +02:00
snippet = {
expand = function(args)
2021-09-24 12:47:15 +02:00
require("luasnip").lsp_expand(args.body)
end
2021-09-06 13:29:42 +02:00
},
mapping = {
2021-11-08 01:29:28 +01:00
["<C-Space>"] = cmp.mapping.complete(),
2021-09-24 12:47:15 +02:00
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm {
2021-09-06 13:29:42 +02:00
behavior = cmp.ConfirmBehavior.Replace,
2021-09-24 12:47:15 +02:00
select = true
2021-09-06 13:29:42 +02:00
},
2021-09-24 12:47:15 +02:00
["<Tab>"] = function(fallback)
2021-09-06 13:29:42 +02:00
if vim.fn.pumvisible() == 1 then
2021-09-24 12:47:15 +02:00
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-n>", true, true, true), "n")
2021-09-06 13:29:42 +02:00
elseif luasnip.expand_or_jumpable() then
2021-09-24 12:47:15 +02:00
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-expand-or-jump", true, true, true), "")
2021-09-06 13:29:42 +02:00
else
fallback()
end
end,
2021-09-24 12:47:15 +02:00
["<S-Tab>"] = function(fallback)
2021-09-06 13:29:42 +02:00
if vim.fn.pumvisible() == 1 then
2021-09-24 12:47:15 +02:00
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-p>", true, true, true), "n")
2021-09-06 13:29:42 +02:00
elseif luasnip.jumpable(-1) then
2021-09-24 12:47:15 +02:00
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<Plug>luasnip-jump-prev", true, true, true), "")
2021-09-06 13:29:42 +02:00
else
fallback()
end
2021-09-24 12:47:15 +02:00
end
2021-09-06 13:29:42 +02:00
},
sources = {
2021-09-24 12:47:15 +02:00
{name = "nvim_lsp"},
{name = "luasnip"},
{name = "path"}
2021-09-24 12:47:15 +02:00
}
}
2021-09-06 13:29:42 +02:00
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
2021-09-24 12:47:15 +02:00
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)