lspserver.getCompletion(1, '')
# locate the start of the word
- var line = getline('.')
- var start = charcol('.') - 1
- var keyword: string = ''
- while start > 0 && line[start - 1] =~ '\k'
- keyword = line[start - 1] .. keyword
- start -= 1
- endwhile
+ var line = getline('.')->strpart(0, col('.') - 1)
+ var keyword = line->matchstr('\k\+$')
lspserver.omniCompleteKeyword = keyword
- return line->byteidx(start)
+ return line->len() - keyword->len()
else
# Wait for the list of matches from the LSP server
var count: number = 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<any> = buf.CurbufGetServerChecked('completion')
+ return !lspserver->empty() && lspserver.omniCompletePending
+enddef
+
# Insert mode completion handler. Used when 24x7 completion is enabled
# (default).
def LspComplete()
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. LSP client can be used as a completion source
+by repurposing `g:LspOmniFunc` function. The adapter which interfaces with
+the external completion engine should invoke this function twice as
+described in |complete-functions|. After the first invocation a request is
+sent to the LSP server to find completion candidates. Second invocation
+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
+called (the second time) only after this function returns `false`.
+
==============================================================================
7. Diagnostics *lsp-diagnostics*