]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add option to enalbe/disable omni-completion
authorYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 28 Jul 2023 04:32:00 +0000 (21:32 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 28 Jul 2023 04:32:00 +0000 (21:32 -0700)
autoload/lsp/completion.vim
autoload/lsp/lsp.vim
autoload/lsp/options.vim
doc/lsp.txt

index 37690a0ff4fc0a3055d76ca28dd710e26ceaba5f..15f59c4ae94c511f59947313ea4c917e465bed79 100644 (file)
@@ -623,7 +623,9 @@ export def BufferInit(lspserver: dict<any>, bnr: number, ftype: string)
                event: 'TextChangedI',
                group: 'LSPBufferAutocmds',
                cmd: 'LspComplete()'})
-  else
+  endif
+
+  if LspOmniComplEnabled(ftype)
     setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc')
   endif
 
@@ -649,4 +651,13 @@ export def BufferInit(lspserver: dict<any>, bnr: number, ftype: string)
   autocmd_add(acmds)
 enddef
 
+# Buffer "bnr" is loaded in a window.  If omni-completion is enabled for this
+# buffer, then set the 'omnifunc' option.
+export def BufferLoadedInWin(bnr: number)
+  if !opt.lspOptions.autoComplete
+      && LspOmniComplEnabled(bnr->getbufvar('&filetype'))
+    setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc')
+  endif
+enddef
+
 # vim: tabstop=8 shiftwidth=2 softtabstop=2
index 930c115efaeeebfd4967b8cc0898c3d9e3d4c6d2..7cf25ac2b5d2172d21fed769c24a6374afae8ed8 100644 (file)
@@ -516,6 +516,7 @@ export def BufferLoadedInWin(bnr: number)
   if opt.lspOptions.autoHighlightDiags
     diag.DiagsRefresh(bnr)
   endif
+  completion.BufferLoadedInWin(bnr)
 enddef
 
 # Stop all the LSP servers
@@ -584,7 +585,13 @@ export def AddServer(serverList: list<dict<any>>)
       continue
     endif
     # Enable omni-completion by default
-    server.omnicompl = server->get('omnicompl', true)
+    var omnicompl_def: bool = false
+    if opt.lspOptions.omniComplete == true
+       || (opt.lspOptions.omniComplete == null
+           && !opt.lspOptions.autoComplete)
+      omnicompl_def = true
+    endif
+    server.omnicompl = server->get('omnicompl', omnicompl_def)
 
     if !server.path->executable()
       if !opt.lspOptions.ignoreMissingServer
index ea35c6cf3854dd9a9020e2e33e5c8198c72b8c02..eae209308f387a14fbe5df58cc6d250c2b7fca24 100644 (file)
@@ -73,6 +73,10 @@ export var lspOptions: dict<any> = {
   # Suppress adding a new line on completion selection with <CR>
   noNewlineInCompletion: false,
 
+  # Omni-completion support.  To keep backward compatibility, this option is
+  # set to null by default instead of false.
+  omniComplete: null,
+
   # Open outline window on right side
   outlineOnRight: false,
 
index c30220b495d7a2ccc6a12ba73d8dc2141f7616c8..dd5325ef6ceb756ed260da27b46fc7c7906f8508 100644 (file)
@@ -552,6 +552,13 @@ noNewlineInCompletion      |Boolean| option.  Suppress adding a new line on
                        completion selection with <CR>.
                        By default this is set to false.
 
+                                               *lsp-opt-omniComplete*
+omniComplete           |Boolean| option. Enables or disables omni-completion.
+                       By default this is set to v:false.  If "autoComplete"
+                       is set to v:false, then omni-completion is enabled by
+                       default.  By setting "omniComplete" option to v:false,
+                       omni-completion can also be disabled.
+
                                                *lsp-opt-outlineOnRight*
 outlineOnRight         |Boolean| option.  Open the outline window on the
                        right side, by default this is false.
@@ -1257,6 +1264,15 @@ do the filtering.  By default, case sensitive comparison is used to filter the
 returned items.  You can modify the 'completionMatcher' option to use either
 case insensitive or fuzzy comparison.
 
+To enable auto completion for all the buffers, set the "autoComplete" option
+to v:true (default).  To disable auto completion for all the buffers, set the
+"autoComplete" option to v:false.  If auto completion is disabled for all the
+buffers, then omni-completion is enabled.  To disable omni-completion for all
+the buffers, set the "omniComplete" option to v:false (default).  To enable
+omni-completion for all the buffers, set the "omniComplete" option to v:true.
+You can also enable or disable omni-completion for a specific language server,
+by setting the "omnicompl" item when registering the language server.
+
 In addition to the automatic completion and omni completion, it is possible to
 use external completion engines.  LSP client can be used as a completion source
 by repurposing `g:LspOmniFunc` function.  The adapter which interfaces with
@@ -1267,7 +1283,7 @@ returns the matches from LSP server.  If the LSP server is not ready to reply
 `g:LspOmniFunc` waits for up to 2 seconds.  This wait blocks the caller from
 doing other work, which may be a concern for asynchronous completion engines.
 To avoid blocking wait call `g:LspOmniCompletePending` function which returns
-`true` immediately if LSP server is not ready.  `g:LspOmniFunc` can be
+`true` immediately if the language server is not ready.  `g:LspOmniFunc` can be
 called (the second time) only after this function returns `false`.
 
 ==============================================================================