neovim: fix completion, fix python lsp

This commit is contained in:
teutat3s 2022-01-05 22:56:03 +01:00
parent 0629024cf5
commit 52e934b3fc
Signed by: teutat3s
GPG key ID: 4FA1D3FA524F22C1
2 changed files with 64 additions and 12 deletions

View file

@ -80,6 +80,7 @@ in
nodePackages.vue-language-server nodePackages.vue-language-server
nodePackages.vscode-langservers-extracted nodePackages.vscode-langservers-extracted
nodePackages.yaml-language-server nodePackages.yaml-language-server
python39Packages.python-lsp-server
python3Full python3Full
python-language-server python-language-server
solargraph solargraph
@ -91,6 +92,12 @@ in
]; ];
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
nvim-cmp
cmp-nvim-lsp
cmp_luasnip
luasnip
lsp_extensions-nvim
nvim-lspconfig nvim-lspconfig
lsp_extensions-nvim lsp_extensions-nvim
completion-nvim completion-nvim

View file

@ -114,7 +114,13 @@ lua <<EOF
}) do -- Setup all of the language servers. † }) do -- Setup all of the language servers. †
if type(lsp_key) == 'number' then -- Enable the LSP with defaults. if type(lsp_key) == 'number' then -- Enable the LSP with defaults.
-- The `lsp` is an index in this case. -- The `lsp` is an index in this case.
nvim_lsp[lsp_settings].setup{['on_attach'] = lsp_setup} nvim_lsp[lsp_settings].setup{
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
capabilities = capabilities,
}
else -- Use the LSP's configuration. else -- Use the LSP's configuration.
local on_attach_setting = on_attach local on_attach_setting = on_attach
@ -125,6 +131,56 @@ lua <<EOF
nvim_lsp[lsp_key].setup(lsp_settings) nvim_lsp[lsp_key].setup(lsp_settings)
end end
end -- end --
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
EOF EOF
" Visualize diagnostics " Visualize diagnostics
@ -143,14 +199,3 @@ autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()
" have a fixed column for the diagnostics to appear in " have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in " this removes the jitter when warnings/errors flow in
set signcolumn=yes set signcolumn=yes
" NeoVim 0.5 Code navigation shortcuts
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.declaration()<CR>