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.
This commit is contained in:
parent
a79bef6c4d
commit
eaec90379d
5 changed files with 49 additions and 24 deletions
|
|
@ -2,13 +2,12 @@
|
|||
autocmd BufEnter * lua require'completion'.on_attach()
|
||||
|
||||
"map <c-p> to manually trigger completion
|
||||
imap <silent> <c-p> <Plug>(completion_trigger)
|
||||
imap <silent> <c-n> <Plug>(completion_trigger)
|
||||
|
||||
" Add <Tab> and <S-Tab> to navigate through popup menu
|
||||
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
|
||||
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
|
||||
|
||||
imap <silent> <c-n> <Plug>(completion_smart_tab)
|
||||
imap <silent> <c-p> <Plug>(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 <silent> <c-j> <Plug>(completion_next_source)
|
||||
imap <silent> <c-k> <Plug>(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': '<c-p>'},
|
||||
\ {'mode': '<c-n>'}
|
||||
\ { 'complete_items': ['buffer', 'lsp', 'snippet']},
|
||||
\ { 'complete_items': ['bibcite'] },
|
||||
\ { 'mode': '<c-p>'},
|
||||
\ { 'mode': '<c-n>'}
|
||||
\],
|
||||
\ 'tex': [
|
||||
\ { 'complete_items': ['buffer', 'lsp', 'snippet']},
|
||||
\ { 'complete_items': ['bibcite'] },
|
||||
\ { 'mode': '<c-p>'},
|
||||
\ { 'mode': '<c-n>'}
|
||||
\],
|
||||
\ 'default': [
|
||||
\ {'complete_items': ['lsp', 'snippet']},
|
||||
\ {'mode': '<c-p>'},
|
||||
\ {'mode': '<c-n>'}
|
||||
\ { 'complete_items': ['lsp', 'snippet']},
|
||||
\ { 'complete_items': [ 'buffers' ] },
|
||||
\ { 'mode': '<c-p>'},
|
||||
\ { 'mode': '<c-n>'}
|
||||
\]
|
||||
\}
|
||||
|
|
|
|||
|
|
@ -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{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue