autoload/lsp/completion.vim | 48 +++++++++++++++++++++--------------------------- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index b3e9c34b72150be963fde579967e85e69ac6aed8..b10ad97e5cb4a8b0121848ec9e7a06e75131a1f1 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -448,12 +448,26 @@ var bnr: number = bufnr() textedit.ApplyTextEdits(bnr, completionData.additionalTextEdits) enddef -# Add buffer-local autocmds for completion -def AddAutocmds(lspserver: dict, bnr: number) +# Initialize buffer-local completion options and autocmds +export def BufferInit(lspserver: dict, bnr: number, ftype: string) + + # buffer-local autocmds for completion var acmds: list> = [] - # Insert-mode completion autocmds (if configured) + # set options for insert mode completion if opt.lspOptions.autoComplete + if lspserver.completionLazyDoc + setbufvar(bnr, '&completeopt', 'menuone,popuphidden,noinsert,noselect') + setbufvar(bnr, '&completepopup', 'width:80,highlight:Pmenu,align:item,border:off') + else + setbufvar(bnr, '&completeopt', 'menuone,popup,noinsert,noselect') + setbufvar(bnr, '&completepopup', 'border:off') + endif + # in insert mode stops completion and inserts a + if !opt.lspOptions.noNewlineInCompletion + :inoremap pumvisible() ? "\\" : "\" + endif + # Trigger 24x7 insert mode completion when text is changed acmds->add({bufnr: bnr, event: 'TextChangedI', @@ -465,6 +479,10 @@ acmds->add({bufnr: bnr, event: 'CompleteChanged', group: 'LSPBufferAutocmds', cmd: 'LspResolve()'}) + endif + else + if LspOmniComplEnabled(ftype) + setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc') endif endif @@ -480,30 +498,6 @@ group: 'LSPBufferAutocmds', cmd: 'LspCompleteDone()'}) autocmd_add(acmds) -enddef - -# Initialize buffer-local completion options and autocmds -export def BufferInit(lspserver: dict, bnr: number, ftype: string) - # set options for insert mode completion - if opt.lspOptions.autoComplete - if lspserver.completionLazyDoc - setbufvar(bnr, '&completeopt', 'menuone,popuphidden,noinsert,noselect') - setbufvar(bnr, '&completepopup', 'width:80,highlight:Pmenu,align:item,border:off') - else - setbufvar(bnr, '&completeopt', 'menuone,popup,noinsert,noselect') - setbufvar(bnr, '&completepopup', 'border:off') - endif - # in insert mode stops completion and inserts a - if !opt.lspOptions.noNewlineInCompletion - :inoremap pumvisible() ? "\\" : "\" - endif - else - if LspOmniComplEnabled(ftype) - setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc') - endif - endif - - AddAutocmds(lspserver, bnr) enddef # vim: tabstop=8 shiftwidth=2 softtabstop=2