]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
API to find out if LSP server has replied
authorGirish Palya <girishji@gmail.com>
Wed, 19 Jul 2023 00:22:16 +0000 (02:22 +0200)
committerGirish Palya <girishji@gmail.com>
Wed, 19 Jul 2023 00:22:16 +0000 (02:22 +0200)
Add a function to find out if LSP server has replied with completion
matches. This is needed in case of using external completion engines
that expect asynchronous callback. LSP client simply acts as a source
of completion items through omnifunc (g:LspOmniFunc). Before calling
the omnifunc the second time g:LspOmniCompletePending can be checked
to see if LSP server is ready to provide completion items.

M  autoload/lsp/completion.vim
M  doc/lsp.txt

autoload/lsp/completion.vim
doc/lsp.txt

index 91971651eef229d686f95be0f6628c93097a5c0e..70bb2ae74269921287b7a8988ddaff15f35dea64 100644 (file)
@@ -488,6 +488,13 @@ def g:LspOmniFunc(findstart: number, base: string): any
   endif
 enddef
 
+# For plugins that implement async completion this function indicates if
+# omnifunc is waiting for LSP response.
+def g:LspOmniCompletePending(): bool
+  var lspserver: dict<any> = buf.CurbufGetServerChecked('completion')
+  return !lspserver->empty() && lspserver.omniCompletePending
+enddef
+
 # Insert mode completion handler. Used when 24x7 completion is enabled
 # (default).
 def LspComplete()
index 7d46ad1b7805bf2fd14e590580969172387dd836..0c60316f978719e33ea1690b2588fc21d654667f 100644 (file)
@@ -1257,6 +1257,18 @@ 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.
 
+In addition to the automatic completion and omni completion, it is possible to
+use external completion engines which provide asynchronous completion
+from various sources. LSP client can be used as a completion source by
+repurposing `g:LspOmniFunc` function. It needs to be invoked twice as
+described in |complete-functions|. After the first invocation a request is
+sent to the LSP server to find completion candidates. Later the function is
+called again to actually obtain the matches. If the LSP server has not replied
+with the matches `g:LspOmniFunc` could wait up to 2 seconds. To avoid blocking
+wait call `g:LspOmniCompletePending` function which returns `true` immediately
+if LSP server is not ready. `g:LspOmniFunc` should be called the second time
+only after this function returns `false`.
+
 ==============================================================================
 7. Diagnostics                                         *lsp-diagnostics*