From d5cd91d1072cda1d2b0ac35723c4de6b470e6e20 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 3 Jan 2022 18:11:23 +0100 Subject: [PATCH] nvim: Add experimental navigator lsp configurator --- nvim/.config/nvim/lua/plug/_lsp.lua | 196 ++++++++-------------------- nvim/.config/nvim/lua/plugins.lua | 41 +++--- 2 files changed, 79 insertions(+), 158 deletions(-) diff --git a/nvim/.config/nvim/lua/plug/_lsp.lua b/nvim/.config/nvim/lua/plug/_lsp.lua index f2a9f72..c54a510 100644 --- a/nvim/.config/nvim/lua/plug/_lsp.lua +++ b/nvim/.config/nvim/lua/plug/_lsp.lua @@ -1,12 +1,6 @@ -local api = vim.api - -local saga = require 'lspsaga' -local lspcfg = require 'lspconfig' local cmp = require 'cmp' local lspkind = require 'lspkind' -require"lsp_signature".setup() - local has_words_before = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and @@ -20,12 +14,6 @@ local feedkey = function(key, mode) mode, true) end --- Enable the following language servers -local servers = { - 'bashls', 'gopls', 'texlab', 'pyright', 'rust_analyzer', 'tsserver', 'vimls' - -- sumneko_lua further down, needs more setup -} - vim.o.completeopt = "menu,menuone,noselect" -- completion items @@ -93,141 +81,71 @@ cmp.setup.cmdline(':', { sources = cmp.config.sources({{name = 'path'}}, {{name = 'cmdline'}}) }) --- Setup lspconfig. -local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp - .protocol - .make_client_capabilities()) - -local on_attach = function(_, _) - -- Keybindings for LSPs - -- Note these are in on_attach so that they don't override bindings in a non-LSP setting - api.nvim_set_keymap("n", "gh", - "lua require 'lspsaga.provider'.lsp_finder()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "gd", - "lua require'lspsaga.provider'.preview_definition()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "gE", - "lua require 'lspsaga.codeaction'.code_action()", - {noremap = true, silent = true}) - api.nvim_set_keymap("v", "gE", - "'<,'>lua require 'lspsaga.codeaction'.range_code_action()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "K", - "lua require('lspsaga.hover').render_hover_doc()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "gK", - "lua require('lspsaga.signaturehelp').signature_help()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "gr", - "lua require('lspsaga.rename').rename()", - {noremap = true, silent = true}) - - api.nvim_set_keymap("n", "ge", - "lua require('lspsaga.diagnostic').show_line_diagnostics()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "]e", - "lua require('lspsaga.diagnostic').lsp_jump_diagnostic_next()", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "[e", - "lua require('lspsaga.diagnostic').lsp_jump_diagnostic_prev()", - {noremap = true, silent = true}) - - api.nvim_set_keymap("n", "C-f", - "lua require('lspsaga.action').smart_scroll_with_saga(1)", - {noremap = true, silent = true}) - api.nvim_set_keymap("n", "C-b", - "lua require('lspsaga.action').smart_scroll_with_saga(-1)", - {noremap = true, silent = true}) - - require("lspsaga").init_lsp_saga { - error_sign = 'X', - warn_sign = '⚠️', - hint_sign = '⚡', - infor_sign = 'ℹ️', - -- code_action_icon = '●', - finder_definition_icon = '📖 ', - finder_reference_icon = '🔖 ', - definition_preview_icon = '📖 ', - finder_action_keys = { - open = '', - split = 's', - vsplit = 'v', - quit = '', - scroll_down = '', - scroll_up = '' - }, - code_action_keys = {quit = '', exec = ''}, - rename_action_keys = {quit = '', exec = ''} - } - vim.cmd("command! LspHover lua vim.lsp.buf.hover()") - vim.cmd( - "command! LspDisable lua vim.lsp.stop_client(vim.lsp.get_active_clients())") - print('LSP ready') -end - --- set up simple servers -for _, lsp in ipairs(servers) do - lspcfg[lsp].setup {on_attach = on_attach, capabilities = capabilities} -end - -lspcfg.efm.setup { - on_attach = on_attach, - init_options = { - documentFormatting = true, - codeAction = true, - completion = true, - documentSymbol = true, - hover = true - }, - filetypes = {"sh"}, - settings = { - rootMarkers = {".git/"}, - languages = { - sh = { - { - lintCommand = 'shellcheck -f gcc -x', - lintFormats = { - '%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', - '%f:%l:%c: %tote: %m' - } - }, {formatCommand = 'shfmt -ci -s -bn', formatStdin = true} - } - } - } -} +require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol + .make_client_capabilities()) -- requires the lua-language-server package to be installed -- The arch package defaults to the following directory local sumneko_root_path = "/usr/share/lua-language-server" -lspcfg.sumneko_lua.setup { - cmd = {"lua-language-server", "-E", sumneko_root_path .. "/main.lua"}, - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = vim.split(package.path, ';') +require'navigator'.setup({ + lsp = { + servers = {'efm'}, + sumneko_lua = { + cmd = { + "lua-language-server", "-E", sumneko_root_path .. "/main.lua" }, - diagnostics = { - -- Get the language server to recognize additional globals - globals = { - 'vim', 'before_each', 'after_each', 'describe', 'it', - 'mock', 'stub' + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = vim.split(package.path, ';') + }, + diagnostics = { + -- Get the language server to recognize additional globals + globals = { + 'vim', 'before_each', 'after_each', 'describe', + 'it', 'mock', 'stub' + } + }, + workspace = { + -- Make the server aware of additional runtime files + library = { + [vim.fn.expand('$VIMRUNTIME/lua')] = true, + [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true, + ["/usr/share/lua/5.1/busted/"] = true + } + } } + } + }, + efm = { + init_options = { + documentFormatting = true, + codeAction = true, + completion = true, + documentSymbol = true, + hover = true }, - workspace = { - -- Make the server aware of additional runtime files - library = { - [vim.fn.expand('$VIMRUNTIME/lua')] = true, - [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true, - ["/usr/share/lua/5.1/busted/"] = true + filetypes = {"sh"}, + settings = { + rootMarkers = {".git/"}, + languages = { + sh = { + { + lintCommand = 'shellcheck -f gcc -x', + lintFormats = { + '%f:%l:%c: %trror: %m', + '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m' + } + }, + {formatCommand = 'shfmt -ci -s -bn', formatStdin = true} + } } } } - }, - on_attach = on_attach -} -saga.init_lsp_saga() + } +}) +require"lsp_signature".setup() diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 0178df4..a9fac2d 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -170,29 +170,10 @@ require("packer").startup(function() use "nvim-telescope/telescope-fzy-native.nvim" use "nvim-telescope/telescope-fzf-writer.nvim" - -- lsp - use 'neovim/nvim-lspconfig' -- some commong language server configurations - use 'tami5/lspsaga.nvim' -- nice and fast ui for lsp actions WILL HAVE TO BE REPLACED SOON - use 'simrat39/symbols-outline.nvim' -- vista-like outline view for code - use 'ray-x/lsp_signature.nvim' - -- and completion - use { - 'hrsh7th/nvim-cmp', -- simple completion engine built specifically for nvim and lsp - requires = { - 'onsails/lspkind-nvim', 'andersevenrud/cmp-tmux', -- completion source from adjacent tmux panes - 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', - 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-vsnip', - 'kdheepak/cmp-latex-symbols', 'ray-x/cmp-treesitter', - 'f3fora/cmp-spell', 'jc-doyle/cmp-pandoc-references', - 'cbarrete/completion-vcard' - } - } -- snippeting use {"hrsh7th/vim-vsnip", event = "InsertEnter"} -- snippet engine use {"rafamadriz/friendly-snippets", event = "InsertEnter"} -- many snippets - require('plug._lsp') - -- treesitter use { 'nvim-treesitter/nvim-treesitter', @@ -222,4 +203,26 @@ require("packer").startup(function() config = function() require('spellsitter').setup() end } + -- lsp + use 'neovim/nvim-lspconfig' -- some commong language server configurations + use 'simrat39/symbols-outline.nvim' -- vista-like outline view for code + use 'ray-x/lsp_signature.nvim' + use { + 'ray-x/navigator.lua', + requires = {'ray-x/guihua.lua', run = 'cd lua/fzy && make'} + } + -- and completion + use { + 'hrsh7th/nvim-cmp', -- simple completion engine built specifically for nvim and lsp + requires = { + 'onsails/lspkind-nvim', 'andersevenrud/cmp-tmux', -- completion source from adjacent tmux panes + 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', + 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-vsnip', + 'kdheepak/cmp-latex-symbols', 'ray-x/cmp-treesitter', + 'f3fora/cmp-spell', 'jc-doyle/cmp-pandoc-references', + 'cbarrete/completion-vcard' + } + } + require('plug._lsp') + end)