neovim: lsp autocompletion

This commit is contained in:
Sijmen 2022-08-12 02:14:31 +02:00
parent eaaef138c3
commit 2c33fbfbc0
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
2 changed files with 57 additions and 4 deletions

View file

@ -58,12 +58,15 @@
plugins = with pkgs.vimPlugins; [
bufferline-nvim
cmp-nvim-lsp
cmp_luasnip
galaxyline-nvim
indentLine
lualine-nvim
luasnip
neorg
nvim-cmp
nvim-colorizer-lua
nvim-compe
nvim-lspconfig
nvim-tree-lua
nvim-treesitter

View file

@ -93,9 +93,59 @@ local on_attach = function(client, bufnr)
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
local lspconfig = require("lspconfig")
lspconfig.rnix.setup { on_attach = on_attach }
lspconfig.pyright.setup { on_attach = on_attach }
lspconfig.rust_analyzer.setup { on_attach = on_attach }
local servers = { "rnix", "pyright", "rust_analyzer" }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
capabilities = capabilities,
}
end
local luasnip = require("luasnip")
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" },
},
}
vim.api.nvim_set_keymap("n", "<C-b>", ":NvimTreeToggle<CR>", { noremap = true, silent = true })