Skip to content

Conversation

@S-furi
Copy link

@S-furi S-furi commented Oct 23, 2025

This PR introduces an alternative way to retrieve autocompletions from compiler server through WebSocket (see KTL-2807 and JetBrains/kotlin-compiler-server#878).

Note: This feature will be disabled by default as by now it is just an alternative and experimental.

The completion retrieval implementation is backed by the built-in WebSocket API.

The protcol between the server and the client consists of 3 kind of frames:

  • init sent on connection, responses will look like Init { sessionId: string, requestId: string? }
  • Completion requests are triggered from the client specifying a requestId (a random UUID) with:
{
  "requestId": "string",
  "completionRequest": {
    "files": [
      {
        "name": "string",
        "text": "string"
      }
    ]
  },
  "line": "int",
  "ch": "int"
}
  • For each completion request a client could either get one of the following frames:
    • Error: { requestId: string?, message: string } in case an error occurred (note: requestId might be empty for errors like a malformed request).
    • Discarded: { requestId: string? } sent as a backpressure mechanism: it informs the client that the request with the associated requestId has been dropped in favor of a more recent request from the same client for the same document.
    • A completion result as follows:
{
  "requestId": "string",
  "completions": [
    {
      "text": "string",
      "displayText": "string",
      "tail": "string?",
      "import": "string?",
      "icon": "Icon?",
      "hasOtherImport": "boolean?"
    }
  ]
}

- Related to KTL-2807: Enhance autocompletion
- LSP-based completion both in REST and WS APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant