From 39294e4b90eb8913e8241bc2dcc2449e3b39447c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Tue, 31 Oct 2023 23:48:01 +0100 Subject: [PATCH] nix: Vim LSP plugins --- .../roles/vim/templates/pluginlist.j2 | 10 -- .../roles/vim/templates/plugins/lightbulb.j2 | 3 - .../vim/templates/plugins/lsp_signature.j2 | 8 -- .../roles/vim/templates/plugins/lspkind.j2 | 6 - .../vim/templates/plugins/nvim_lspconfig.j2 | 70 ------------ .../roles/vim/templates/plugins/vim_lsp.j2 | 39 ------- config/nix/hm/dev.nix | 16 --- config/nix/hm/vim.nix | 103 ++++++++++++++---- config/nix/hm/vim/lsp_signature-nvim.lua | 3 + 9 files changed, 85 insertions(+), 173 deletions(-) delete mode 100644 config/automatrop/roles/vim/templates/plugins/lightbulb.j2 delete mode 100644 config/automatrop/roles/vim/templates/plugins/lsp_signature.j2 delete mode 100644 config/automatrop/roles/vim/templates/plugins/lspkind.j2 delete mode 100644 config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 delete mode 100644 config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 create mode 100644 config/nix/hm/vim/lsp_signature-nvim.lua diff --git a/config/automatrop/roles/vim/templates/pluginlist.j2 b/config/automatrop/roles/vim/templates/pluginlist.j2 index 277cc90..abaa6be 100644 --- a/config/automatrop/roles/vim/templates/pluginlist.j2 +++ b/config/automatrop/roles/vim/templates/pluginlist.j2 @@ -16,16 +16,6 @@ " Theme source ~/.config/vim/theme.vim -" Language Server Client -{% if variant == 'nvim' %} -{{ use_plugin('nvim_lspconfig') }} -{{ use_plugin('lightbulb') }} -{{ use_plugin('lspkind') }} -{{ use_plugin('lsp_signature') }} -{% else %} -{{ use_plugin('vim_lsp') }} -{% endif %} - " Treesitter {% if variant == 'nvim' %} {{ use_plugin('treesitter') }} diff --git a/config/automatrop/roles/vim/templates/plugins/lightbulb.j2 b/config/automatrop/roles/vim/templates/plugins/lightbulb.j2 deleted file mode 100644 index 426fbd8..0000000 --- a/config/automatrop/roles/vim/templates/plugins/lightbulb.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{# Shows a lightbulb whenever a codeAction is available under the cursor #} -{{ add_source('kosayoda/nvim-lightbulb') -}} -autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb() diff --git a/config/automatrop/roles/vim/templates/plugins/lsp_signature.j2 b/config/automatrop/roles/vim/templates/plugins/lsp_signature.j2 deleted file mode 100644 index 918a056..0000000 --- a/config/automatrop/roles/vim/templates/plugins/lsp_signature.j2 +++ /dev/null @@ -1,8 +0,0 @@ -{# Show argument documentation when typing a function #} -{{ add_source('ray-x/lsp_signature.nvim') -}} - -lua << EOF -require'lsp_signature'.on_attach({ - hint_enable = false, -}) -EOF diff --git a/config/automatrop/roles/vim/templates/plugins/lspkind.j2 b/config/automatrop/roles/vim/templates/plugins/lspkind.j2 deleted file mode 100644 index d81e404..0000000 --- a/config/automatrop/roles/vim/templates/plugins/lspkind.j2 +++ /dev/null @@ -1,6 +0,0 @@ -{# Add icons to LSP completions #} -{{ add_source('onsails/lspkind-nvim') -}} - -lua << EOF -require('lspkind').init() -EOF diff --git a/config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 b/config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 deleted file mode 100644 index de7fb38..0000000 --- a/config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 +++ /dev/null @@ -1,70 +0,0 @@ -{# LSP client for neovim ≥ 0.5 #} -{{ add_source('neovim/nvim-lspconfig') -}} -lua << EOF -local nvim_lsp = require('lspconfig') - --- Mappings. --- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap=true, silent=true } -vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) -vim.keymap.set('n', '[e', vim.diagnostic.goto_prev, opts) -vim.keymap.set('n', ']e', vim.diagnostic.goto_next, opts) --- vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) - --- Use an on_attach function to only map the following keys --- after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap=true, silent=true, buffer=bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) --- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) --- vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) --- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) -end - --- Use a loop to conveniently call 'setup' on multiple servers and --- map buffer local keybindings when the language server attaches -local servers = { -{% if 'ansible' in dev_stuffs %} - "ansiblels", -{% endif %} -{% if 'nix' in dev_stuffs %} - "rnix", -{% endif %} -{% if 'perl' in dev_stuffs %} - "perlls", -{% endif %} -{% if 'python' in dev_stuffs %} - "pylsp", -{% endif %} -{% if 'php' in dev_stuffs %} - "phpactor", -- Install this one manually https://phpactor.readthedocs.io/en/master/usage/standalone.html#global-installation -{% endif %} -{% if 'sql' in dev_stuffs %} - "sqlls", -{% endif %} -} -for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - } - } -end -EOF diff --git a/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 b/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 deleted file mode 100644 index dfd0d2e..0000000 --- a/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 +++ /dev/null @@ -1,39 +0,0 @@ -{# LSP client for Vim8 and neovim #} -{{ add_source('prabirshrestha/vim-lsp') -}} -{{ add_source('mattn/vim-lsp-settings') -}} -" (providers are automatically detected thanks to vim-lsp-settings. -" You can even install some locally using :LspInstallServer) - -let g:lsp_signs_enabled = 1 -let g:lsp_diagnostics_echo_cursor = 1 - -let g:lsp_signs_error = {'text': '✗'} -let g:lsp_signs_warning = {'text': '‼'} -let g:lsp_signs_information = {'text': 'ℹ'} -let g:lsp_signs_hint = {'text': '?'} - -let g:lsp_highlight_references_enabled = 1 - -function! s:on_lsp_buffer_enabled() abort - setlocal omnifunc=lsp#complete - setlocal signcolumn=yes - if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif - nmap gd (lsp-definition) - nmap gD (lsp-declaration) - nmap gr (lsp-references) - nmap gi (lsp-implementation) - nmap rn (lsp-rename) - nmap [d (lsp-previous-diagnostic) - nmap ]d (lsp-next-diagnostic) - nmap K (lsp-hover) - nmap f (lsp-document-format) - vmap f (lsp-document-range-format) - inoremap lsp#scroll(+4) - inoremap lsp#scroll(-4) -endfunction - -augroup lsp_install - au! - " call s:on_lsp_buffer_enabled only for languages that has the server registered. - autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() -augroup END diff --git a/config/nix/hm/dev.nix b/config/nix/hm/dev.nix index 7e9f634..b2b5c66 100644 --- a/config/nix/hm/dev.nix +++ b/config/nix/hm/dev.nix @@ -6,7 +6,6 @@ # Ansible ansible ansible-lint - ansible-language-server # C/C++ cmake @@ -42,24 +41,9 @@ # nix nix - rnix-lsp - - # Perl - perl536Packages.PLS # Python - mypy - python3Packages.black - python3Packages.python-lsp-server - python3Packages.pylsp-mypy - python3Packages.pyls-isort - python3Packages.python-lsp-black - # TODO Are all those for the same language server? python3Packages.ipython - - # Bash - nodePackages.bash-language-server - sqls ]; } diff --git a/config/nix/hm/vim.nix b/config/nix/hm/vim.nix index 19c7165..b9428f7 100644 --- a/config/nix/hm/vim.nix +++ b/config/nix/hm/vim.nix @@ -54,27 +54,27 @@ in # Go to whatever telescope = { enable = true; - # FIXME Crashes nvim on startup, complaining about some keymap - # keymaps = { - # gF = "find_files"; - # gf = "git_files"; - # gB = "buffers"; - # gl = "current_buffer_fuzzy_find"; - # gL = "live_grep"; - # gT = "tags"; - # gt = "treesitter"; - # gm = "marks"; - # gh = "oldfiles"; - # gH = "command_history"; - # gS = "search_history"; - # gC = "commands"; - # gr = "lsp_references"; - # ga = "lsp_code_actions"; - # ge = "lsp_document_diagnostics"; - # gE = "lsp_workspace_diagnostics"; - # gd = "lsp_definitions"; - # gs = "lsp_document_symbols"; - # }; + keymaps = { + gF = "find_files"; + gf = "git_files"; + gB = "buffers"; + gl = "current_buffer_fuzzy_find"; + gL = "live_grep"; + gT = "tags"; + gt = "treesitter"; + gm = "marks"; + gh = "oldfiles"; + gH = "command_history"; + gS = "search_history"; + gC = "commands"; + gr = "lsp_references"; + # ga = "lsp_code_actions"; + # ge = "lsp_document_diagnostics"; + # gE = "lsp_workspace_diagnostics"; + # FIXME Above makes nvim crash on startup, action is not provided + gd = "lsp_definitions"; + gs = "lsp_document_symbols"; + }; defaults = { vimgrep_arguments = [ "${pkgs.ripgrep}/bin/rg" @@ -97,6 +97,63 @@ in # Surrounding pairs surround.enable = true; # Change surrounding pairs (e.g. brackets, quotes) + + # Language Server + lsp = { + enable = true; + keymaps = { + silent = true; + diagnostic = { + "e" = "open_float"; + "[e" = "goto_prev"; + "]e" = "goto_next"; + }; + lspBuf = { + "gD" = "declaration"; + "K" = "hover"; + "gi" = "implementation"; + "" = "signature_help"; + "wa" = "add_workspace_folder"; + "wr" = "remove_workspace_folder"; + # "wl" = "list_workspace_folder"; + # TODO Full thing was function() print(vim.inspect(vim.lsp.buf.list_workspace_folder())) end but not sure I'm ever really using this + # Also makes nvim crash like this, so uncommented + "D" = "type_definition"; + "rn" = "rename"; + "f" = "format"; + # TODO Full thing was function() vim.lsp.buf.format { async = true } end, so async while this isn't + # Maybe replace this with lsp-format? + }; + }; + servers = { + # FIXME ansiblels + bashls.enable = true; # Bash + jsonls.enable = true; # JSON + # FIXME perlls + pylsp = { # Python + enable = true; + settings.plugins = { + black.enabled = true; + flake8.enabled = true; # FIXME Not getting the warnings I would expect + isort.enabled = true; + pylsp_mypy.enabled = true; + }; + }; + # FIXME phpactor. Only from 23.11 + # phpactor.enable = true; # PHP + rnix-lsp.enable = true; # Nix + # FIXME sqlls + yamlls.enable = true; # Nix + # TODO Check out none-ls + }; + # FIXME vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') as onAttach... is it needed? + # FIXME flags = { debounce_text_changes = 150 } is the default value ok? Maybe it was actually ignored + }; + nvim-lightbulb = { # Shows a lightbulb whenever a codeAction is available under the cursor + enable = true; + autocmd.enabled = true; + }; + lspkind.enable = true; # Add icons to LSP completions }; extraPlugins = with pkgs.vimPlugins; [ nvim-scrollview # Scroll bar @@ -125,10 +182,14 @@ in vim-gutentags # Generate tags symbols-outline-nvim # Show a symbol panel on the right # TODO Fails on startup. Same on Arch. Config issue? + + # Language server + lsp_signature-nvim # Show argument definition when typing a function ]; extraConfigLua = lib.strings.concatMapStringsSep "\n" (f: builtins.readFile f) [ ./vim/feline.lua ./vim/symbols-outline-nvim.lua + ./vim/lsp_signature-nvim.lua ]; extraConfigVim = '' " vim-gutentags diff --git a/config/nix/hm/vim/lsp_signature-nvim.lua b/config/nix/hm/vim/lsp_signature-nvim.lua new file mode 100644 index 0000000..4f5fff7 --- /dev/null +++ b/config/nix/hm/vim/lsp_signature-nvim.lua @@ -0,0 +1,3 @@ +require'lsp_signature'.on_attach({ + hint_enable = false, +})