From eaec90379de981e544c23fb2f46d19c28108c086 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 2 Oct 2020 11:50:31 +0200 Subject: [PATCH] nvim: Improve lsp source chaining Lsp will by default invoke most of its sources simultaneously (one after the other if no completions are found for the first), but this is disabled for pandoc. In pandoc, only the buffer and lsp sources are invoked (the first chain), since bibcite will take a while to compile the cite keys. To invoke bibcite in pandoc, use c-j/c-k when in the completion menu, and they will be calculated. This may be removed if a faster compilation for bibtex citekeys is found. --- bootstrap/packages.txt | 5 ++ nvim/.config/nvim/init.vim | 4 ++ nvim/.config/nvim/plugin/completion-nvim.vim | 56 ++++++++++++-------- nvim/.config/nvim/plugin/nvim-lspconfig.vim | 7 ++- nvim/.config/nvim/watch.lua | 1 + 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/bootstrap/packages.txt b/bootstrap/packages.txt index 7b1335b..a2fef4c 100644 --- a/bootstrap/packages.txt +++ b/bootstrap/packages.txt @@ -9,6 +9,7 @@ aspell-de aspell-en atool barrier +bash-language-server bat bc biber @@ -34,6 +35,7 @@ glances glow gnome-keyring go +gopls grub hugo i3-gaps @@ -90,6 +92,7 @@ psmisc pulsemixer python-black python-jedi +python-language-server python-pdfminer.six python-pipx python-pybtex @@ -115,6 +118,7 @@ surfraw sxhkd systemd-sysvcompat tdrop-git +texlab texlive-bibtexextra texlive-fontsextra texlive-formatsextra @@ -138,6 +142,7 @@ usbutils vagrant vi vifm +vim-language-server xcape xclip xorg-xev diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim index c53ccda..74ef82c 100644 --- a/nvim/.config/nvim/init.vim +++ b/nvim/.config/nvim/init.vim @@ -53,6 +53,7 @@ Plug 'junegunn/fzf.vim' Plug 'neovim/nvim-lspconfig' " some commong language server configurations Plug 'nvim-lua/completion-nvim' " simple completion engine built specifically for nvim and lsp +Plug 'steelsojka/completion-buffers' " completion source from words found in current buffers Plug 'desmap/ale-sensible' | Plug 'w0rp/ale' " asynchronous linting - might be superseded by lsp or coc.nvim at some point " statusline Plug 'vim-airline/vim-airline' @@ -189,6 +190,9 @@ set noequalalways " make sure there's always *some* context below cursor set scrolloff=5 +" in .tex files, default to latex over plaintext/context as syntax +let g:tex_flavor = "latex" + " }}} " KEYBINDINGS {{{ " ================================================================================ diff --git a/nvim/.config/nvim/plugin/completion-nvim.vim b/nvim/.config/nvim/plugin/completion-nvim.vim index 79938d3..4cafb23 100644 --- a/nvim/.config/nvim/plugin/completion-nvim.vim +++ b/nvim/.config/nvim/plugin/completion-nvim.vim @@ -2,13 +2,12 @@ autocmd BufEnter * lua require'completion'.on_attach() "map to manually trigger completion -imap (completion_trigger) -imap (completion_trigger) - -" Add and to navigate through popup menu -inoremap pumvisible() ? "\" : "\" -inoremap pumvisible() ? "\" : "\" - +imap (completion_smart_tab) +imap (completion_smart_s_tab) +" switch between completion sources manually with c-j/c-k +" only do so if popupmenu is visible, otherwise normal function +imap (completion_next_source) +imap (completion_previous_source) " Set completeopt to have a better completion experience set completeopt=menuone,noinsert,noselect @@ -22,38 +21,49 @@ let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy'] " even when backtracking enable completion let g:completion_trigger_on_delete = 1 +" switch between different completion changes when no completions found for +" current one +let g:completion_auto_change_source = 1 + " register new completion engines " (set in rtp/lua/*_complete.lua) " " pandoc citation key completion lua require'completion'.addCompletionSource('bibcite', require'pandoc_complete'.complete_item) -" only call for specified shortcut, or with completion keys +" in pandoc files, normal completion should only come from buffer sources and +" bibcite only invoked manually, since it takes long to parse augroup pandocCompletion - autocmd! - autocmd BufEnter * call SetupPandocCompletion() + autocmd! + autocmd BufEnter * call SetupPandocCompletion() augroup end fun! SetupPandocCompletion() - if &ft =~ 'pandoc' - let g:completion_enable_auto_popup = 0 - let g:completion_trigger_character = ['@\w*'] - return - endif - let g:completion_enable_auto_popup = 1 - let g:completion_trigger_character = ['.'] + if &ft =~ 'pandoc' + let g:completion_auto_change_source = 1 + return + endif + let g:completion_auto_change_source = 0 endfun " the completion chains for different filetypes " see https://github.com/nvim-lua/completion-nvim/wiki/chain-complete-support let g:completion_chain_complete_list = { \ 'pandoc': [ - \ {'complete_items': ['bibcite', 'lsp', 'snippet']}, - \ {'mode': ''}, - \ {'mode': ''} + \ { 'complete_items': ['buffer', 'lsp', 'snippet']}, + \ { 'complete_items': ['bibcite'] }, + \ { 'mode': ''}, + \ { 'mode': ''} + \], + \ 'tex': [ + \ { 'complete_items': ['buffer', 'lsp', 'snippet']}, + \ { 'complete_items': ['bibcite'] }, + \ { 'mode': ''}, + \ { 'mode': ''} \], \ 'default': [ - \ {'complete_items': ['lsp', 'snippet']}, - \ {'mode': ''}, - \ {'mode': ''} + \ { 'complete_items': ['lsp', 'snippet']}, + \ { 'complete_items': [ 'buffers' ] }, + \ { 'mode': ''}, + \ { 'mode': ''} \] \} diff --git a/nvim/.config/nvim/plugin/nvim-lspconfig.vim b/nvim/.config/nvim/plugin/nvim-lspconfig.vim index 9561622..128e0d4 100644 --- a/nvim/.config/nvim/plugin/nvim-lspconfig.vim +++ b/nvim/.config/nvim/plugin/nvim-lspconfig.vim @@ -1,4 +1,9 @@ - " enable python language servers lua require'nvim_lsp'.pyls.setup{} lua require'nvim_lsp'.vimls.setup{} +lua require'nvim_lsp'.bashls.setup{} +lua require'nvim_lsp'.gopls.setup{} +lua require'nvim_lsp'.texlab.setup{} + +" requires manual `:LspInstall sumneko_lua` +lua require'nvim_lsp'.sumneko_lua.setup{} diff --git a/nvim/.config/nvim/watch.lua b/nvim/.config/nvim/watch.lua index aec2ad2..4c82035 100644 --- a/nvim/.config/nvim/watch.lua +++ b/nvim/.config/nvim/watch.lua @@ -14,3 +14,4 @@ function watch_file(fname) end vim.api.nvim_command( "command! -nargs=1 Watch call luaeval('watch_file(_A)', expand(''))") +