add autocomplete

This commit is contained in:
Charlotte 🦝 Delenk 2022-06-13 14:10:34 +01:00
parent 343676a241
commit a6e9c4efd6
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122
3 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,41 @@
-- nvim-cmp setup
local cmp = require("cmp")
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}

View file

@ -35,6 +35,13 @@ in {
}
copilot-vim
rust-vim # for proper syntax highlighting
luasnip
cmp-nvim-lsp
cmp_luasnip
{
plugin = nvim-cmp;
config = "lua dofile(\"${./cmp.lua}\")";
}
{
plugin = nvim-lspconfig;
config = "lua dofile(\"${./lsp.lua}\")";

View file

@ -1,3 +1,7 @@
-- Grab capabilties
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
@ -41,6 +45,7 @@ for _, lsp in pairs(servers) do
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
},
capabilities = capabilities
}
end