autoload/lsp/completion.vim | 7 +++++++ doc/lsp.txt | 12 ++++++++++++ diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 91971651eef229d686f95be0f6628c93097a5c0e..70bb2ae74269921287b7a8988ddaff15f35dea64 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -488,6 +488,13 @@ return res->filter((i, v) => v.word->stridx(prefix) == 0) 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 = buf.CurbufGetServerChecked('completion') + return !lspserver->empty() && lspserver.omniCompletePending +enddef + # Insert mode completion handler. Used when 24x7 completion is enabled # (default). def LspComplete() diff --git a/doc/lsp.txt b/doc/lsp.txt index 7d46ad1b7805bf2fd14e590580969172387dd836..0c60316f978719e33ea1690b2588fc21d654667f 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -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*