serverCompletionSource

fun serverCompletionSource(client: LSPClient, uri: String, config: ServerCompletionConfig = ServerCompletionConfig()): SuspendCompletionSource

The suspend completion source that requests completions from the language server wrapped by client for the file at uri.

Ports upstream @codemirror/lsp-client's serverCompletionSource:

  • If the server has no completionProvider capability, returns null.

  • For implicit (non-explicit) triggers, only fires when the character before the cursor is an identifier char ([A-Za-z_]) or one of the server's advertised triggerCharacters.

  • Flushes pending document changes (LSPClient.sync) before requesting.

  • Requests textDocument/completion at the cursor, maps the result via mapCompletionItem, and resolves the apply range via completionResultRange.

  • Uses config's validFor or, failing that, prefixRegexp.

Cancellation: there is no explicit $/cancelRequest. The autocomplete machinery cancels the coroutine running this source when the user types again (the agreed design); the in-flight textDocumentCompletion call is cancelled cooperatively through structured concurrency. (Upstream instead sends an explicit cancel notification.)

isIncomplete: the result always carries a validFor prefix regex (from config or prefixRegexp), even when the server marks the list incomplete, so :autocomplete narrows the already-returned items by the typed prefix as the user types. Many servers mark every member list isIncomplete = true; gating validFor on that flag left such lists unfiltered (and the accept range stale), so it is set unconditionally (#114).