Skip to content

Kotlin LSP not working (timeouts, no pull-diagnostics, etc.) #23873

@lowlyocean

Description

@lowlyocean

Description

Re-opening this issue as suggested by the bot, because it's very much still a problem

I went through the code and... it's a mess. I'm seriously considering not using opencode anymore :D

But what I found out, for example, is that the cos are wrong. It definitely uses kotlin-lsp () and not kotlin-ls.

I'll try to fix a few bugs, update the docs, and create a PR for it.

Here's a summary after the analysis:

- Built-in Kotlin LSP is Kotlin/kotlin-lsp (JetBrains), not fwcd: the built-in server is id: "kotlin-ls" but it downloads from https://api.github.com/repos/Kotlin/kotlin-lsp/releases/latest and launches kotlin-lsp.sh/kotlin-lsp.cmd. See packages/opencode/src/lsp/server.ts:1231.
- fwcd/kotlin-language-server is not used anywhere: repo search finds no references to fwcd / kotlin-language-server (only the docs/config examples from the issue discussion; not in code).
- Why diagnostics don’t reach the agent:
      - The LSP client only consumes push diagnostics via textDocument/publishDiagnostics (packages/opencode/src/lsp/client.ts:52).
    - There is no implementation for pull diagnostics (textDocument/diagnostic / workspace/diagnostic) in packages/opencode/src/lsp/*, so servers that primarily use pull-diagnostics will produce {} in LSP.diagnostics() even if they’re “working”.
    - Even when diagnostics exist, they’re only appended to tool outputs after write-like actions (write/edit/apply_patch) (packages/opencode/src/tool/write.ts:56, packages/opencode/src/tool/edit.ts:132). A normal read just “warms” LSP without waiting (packages/opencode/src/tool/read.ts:132).
- Why symbol info doesn’t reach the agent (this one is a hard blocker):
    - The HTTP route that should expose workspace symbol search is currently stubbed to always return [] (packages/opencode/src/server/routes/file.ts:86).
    - The lsp tool’s workspaceSymbol operation ignores the user query and calls LSP.workspaceSymbol("") (packages/opencode/src/tool/lsp.ts:72), so even direct tool usage is effectively broken for searching.
- Docs are misleading/out-of-date for Kotlin naming: packages/web/src/content/docs/lsp.mdx:30 lists kotlin-ls as the built-in server, but doesn’t mention it actually installs/launches kotlin-lsp from Kotlin/kotlin-lsp—easy to interpret as a different server.

Originally posted by @mrclrchtr in #3116


Steps to reproduce

Install kotlin-lsp, make it available in the PATH, add to opencode.json as shown below, and run command OPENCODE_EXPERIMENTAL_LSP_TOOL=true bun dev debug lsp diagnostics <path_to>/somefile.kt --print-logs --log-level DEBUG

  "lsp": {
    "kotlin-ls": {
      "disabled": true,
    },
    "kotlin-lsp": {
      "command": ["kotlin-lsp", "--stdio"],
      "extensions": [".kt", ".kts"]
    }
  }

Additional context


Expected behavior

Command should produce a response rather than empty {} response. Also, reading/writing actions should cause LSP to load in the TUI sidebar


Actual behavior

Empty reply

Plugins

OpenCode version

1.14.20

Screenshot and/or share link

N/A

Operating System

Windows 11

Terminal

WSL

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions