nvim: Add experimental navigator lsp configurator

This commit is contained in:
Marty Oehme 2022-01-03 18:11:23 +01:00
parent ff0ddb2b2d
commit d5cd91d107
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 79 additions and 158 deletions

View file

@ -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",
"<cmd>lua require 'lspsaga.provider'.lsp_finder()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "gd",
"<cmd>lua require'lspsaga.provider'.preview_definition()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "gE",
"<cmd>lua require 'lspsaga.codeaction'.code_action()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("v", "gE",
"<cmd>'<,'>lua require 'lspsaga.codeaction'.range_code_action()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "K",
"<cmd>lua require('lspsaga.hover').render_hover_doc()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "gK",
"<cmd>lua require('lspsaga.signaturehelp').signature_help()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "gr",
"<cmd>lua require('lspsaga.rename').rename()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "ge",
"<cmd>lua require('lspsaga.diagnostic').show_line_diagnostics()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "]e",
"<cmd>lua require('lspsaga.diagnostic').lsp_jump_diagnostic_next()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "[e",
"<cmd>lua require('lspsaga.diagnostic').lsp_jump_diagnostic_prev()<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "C-f",
"<cmd>lua require('lspsaga.action').smart_scroll_with_saga(1)<CR>",
{noremap = true, silent = true})
api.nvim_set_keymap("n", "C-b",
"<cmd>lua require('lspsaga.action').smart_scroll_with_saga(-1)<CR>",
{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 = '<cr>',
split = 's',
vsplit = 'v',
quit = '<esc>',
scroll_down = '<c-f>',
scroll_up = '<c-b>'
},
code_action_keys = {quit = '<esc>', exec = '<cr>'},
rename_action_keys = {quit = '<esc>', exec = '<cr>'}
}
vim.cmd("command! LspHover lua vim.lsp.buf.hover()<CR>")
vim.cmd(
"command! LspDisable lua vim.lsp.stop_client(vim.lsp.get_active_clients())<CR>")
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()

View file

@ -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)