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; [ plugins = with pkgs.vimPlugins; [
bufferline-nvim bufferline-nvim
cmp-nvim-lsp
cmp_luasnip
galaxyline-nvim galaxyline-nvim
indentLine indentLine
lualine-nvim lualine-nvim
luasnip
neorg neorg
nvim-cmp
nvim-colorizer-lua nvim-colorizer-lua
nvim-compe
nvim-lspconfig nvim-lspconfig
nvim-tree-lua nvim-tree-lua
nvim-treesitter 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) vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
end end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
lspconfig.rnix.setup { on_attach = on_attach } local servers = { "rnix", "pyright", "rust_analyzer" }
lspconfig.pyright.setup { on_attach = on_attach } for _, lsp in ipairs(servers) do
lspconfig.rust_analyzer.setup { on_attach = on_attach } 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 }) vim.api.nvim_set_keymap("n", "<C-b>", ":NvimTreeToggle<CR>", { noremap = true, silent = true })