From 8229dea533c7ea9d273cef1af4a45718261ead87 Mon Sep 17 00:00:00 2001 From: teutat3s Date: Wed, 5 Jan 2022 22:56:03 +0100 Subject: [PATCH] neovim: fix completion, fix python lsp --- modules/terminal-life/nvim/default.nix | 8 +- modules/terminal-life/nvim/lsp.vim | 111 +++++++++++++++++++++---- 2 files changed, 100 insertions(+), 19 deletions(-) diff --git a/modules/terminal-life/nvim/default.nix b/modules/terminal-life/nvim/default.nix index 2d4a8ee9..e46c82e2 100644 --- a/modules/terminal-life/nvim/default.nix +++ b/modules/terminal-life/nvim/default.nix @@ -78,7 +78,7 @@ in nodePackages.vscode-html-languageserver-bin nodePackages.vscode-json-languageserver-bin nodePackages.yaml-language-server - python-language-server + python39Packages.python-lsp-server python3Full solargraph rnix-lsp @@ -88,7 +88,11 @@ in ]; plugins = with pkgs.vimPlugins; [ - completion-nvim + nvim-cmp + cmp-nvim-lsp + cmp_luasnip + luasnip + lsp_extensions-nvim nvim-lspconfig diff --git a/modules/terminal-life/nvim/lsp.vim b/modules/terminal-life/nvim/lsp.vim index 519330f8..1d5bf4d4 100644 --- a/modules/terminal-life/nvim/lsp.vim +++ b/modules/terminal-life/nvim/lsp.vim @@ -14,11 +14,44 @@ set shortmess+=c " https://gitlab.com/Iron_E/dotfiles/-/blob/master/.config/nvim/lua/_config/plugin/nvim_lsp.lua lua < + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + end + -- Add additional capabilities supported by nvim-cmp + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + for lsp_key, lsp_settings in pairs({ 'bashls', ------------------------------- Bash 'ccls', --------------------------------- C / C++ / Objective-C @@ -46,7 +79,7 @@ lua <'] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = 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 " Visualize diagnostics @@ -105,14 +193,3 @@ autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics({ focusable = " have a fixed column for the diagnostics to appear in " this removes the jitter when warnings/errors flow in set signcolumn=yes - -" NeoVim 0.5 Code navigation shortcuts -nnoremap gd lua vim.lsp.buf.definition() -nnoremap K lua vim.lsp.buf.hover() -nnoremap gD lua vim.lsp.buf.implementation() -nnoremap lua vim.lsp.buf.signature_help() -nnoremap 1gD lua vim.lsp.buf.type_definition() -nnoremap gr lua vim.lsp.buf.references() -nnoremap g0 lua vim.lsp.buf.document_symbol() -nnoremap gW lua vim.lsp.buf.workspace_symbol() -nnoremap lua vim.lsp.buf.declaration()