]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Merge the functions "AddAutocmds" and "BufferInit"
authorAndreas Louv <andreas@louv.dk>
Thu, 30 Mar 2023 12:58:05 +0000 (14:58 +0200)
committerAndreas Louv <andreas@louv.dk>
Sun, 2 Apr 2023 21:32:25 +0000 (23:32 +0200)
autoload/lsp/completion.vim

index b3e9c34b72150be963fde579967e85e69ac6aed8..b10ad97e5cb4a8b0121848ec9e7a06e75131a1f1 100644 (file)
@@ -448,12 +448,26 @@ def LspCompleteDone()
   textedit.ApplyTextEdits(bnr, completionData.additionalTextEdits)
 enddef
 
-# Add buffer-local autocmds for completion
-def AddAutocmds(lspserver: dict<any>, bnr: number)
+# Initialize buffer-local completion options and autocmds
+export def BufferInit(lspserver: dict<any>, bnr: number, ftype: string)
+
+  # buffer-local autocmds for completion
   var acmds: list<dict<any>> = []
 
-  # 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
+    # <Enter> in insert mode stops completion and inserts a <Enter>
+    if !opt.lspOptions.noNewlineInCompletion
+      :inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
+    endif
+
     # Trigger 24x7 insert mode completion when text is changed
     acmds->add({bufnr: bnr,
                event: 'TextChangedI',
@@ -466,6 +480,10 @@ def AddAutocmds(lspserver: dict<any>, bnr: number)
                  group: 'LSPBufferAutocmds',
                  cmd: 'LspResolve()'})
     endif
+  else
+    if LspOmniComplEnabled(ftype)
+      setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc')
+    endif
   endif
 
   acmds->add({bufnr: bnr,
@@ -482,28 +500,4 @@ def AddAutocmds(lspserver: dict<any>, bnr: number)
   autocmd_add(acmds)
 enddef
 
-# Initialize buffer-local completion options and autocmds
-export def BufferInit(lspserver: dict<any>, 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
-    # <Enter> in insert mode stops completion and inserts a <Enter>
-    if !opt.lspOptions.noNewlineInCompletion
-      :inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
-    endif
-  else
-    if LspOmniComplEnabled(ftype)
-      setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc')
-    endif
-  endif
-
-  AddAutocmds(lspserver, bnr)
-enddef
-
 # vim: tabstop=8 shiftwidth=2 softtabstop=2