Kotlin LSP support #2061

Open
opened 2026-02-16 17:33:59 -05:00 by yindo · 8 comments
Owner

Originally created by @Melodeiro on GitHub (Oct 12, 2025).

Originally assigned to: @rekram1-node on GitHub.

There are not that bad LSP server for kotlin. I'm struggling to connect it (im on a windows), maybe im doing something wrong. But having a first-class support for it would be great: https://github.com/Kotlin/kotlin-lsp

Problem when im trying to connect it on windows is that opencode sends wrong file paths to it, like file:///C:\dir\file, or something like that. I tried to use WSL, but it doesn't responds to queries. Or does latter means, that Kotlin LSP just isn't ready for opencode yet? Not sure that it supports all necessary functions right now

Originally created by @Melodeiro on GitHub (Oct 12, 2025). Originally assigned to: @rekram1-node on GitHub. There are not that bad LSP server for kotlin. I'm struggling to connect it (im on a windows), maybe im doing something wrong. But having a first-class support for it would be great: https://github.com/Kotlin/kotlin-lsp Problem when im trying to connect it on windows is that opencode sends wrong file paths to it, like file:///C:\dir\file, or something like that. I tried to use WSL, but it doesn't responds to queries. Or does latter means, that Kotlin LSP just isn't ready for opencode yet? Not sure that it supports all necessary functions right now
yindo added the help-wanted label 2026-02-16 17:33:59 -05:00
Author
Owner

@rekram1-node commented on GitHub (Oct 12, 2025):

first class support makes sense, as for lsp file path issues that may be an issue we have with windows…

@itsrainingmani have u noticed any lsp issues on windows?

@rekram1-node commented on GitHub (Oct 12, 2025): first class support makes sense, as for lsp file path issues that may be an issue we have with windows… @itsrainingmani have u noticed any lsp issues on windows?
Author
Owner

@iwauo commented on GitHub (Oct 17, 2025):

I think kotlin‑lsp works with opencode.ai on Unix‑like systems, including WSL.
I use it on both Linux and macOS with the following setup:

  1. Follow the installation instructions at https://github.com/Kotlin/kotlin-lsp.
  2. Add the following configuration to your opencode.json:
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "llama-cpp": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Llama.cpp (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "gpt-oss-20B": {
          "name": "unsloth/gpt-oss-20b-GGUF:Q4_K_M"
        }
      }
    }
  },
  "lsp": {
+    "kotlin-lsp": {
+     "command": ["kotlin-lsp"],
+      "extensions": [".kt"]
+    }
  }
}
@iwauo commented on GitHub (Oct 17, 2025): I think `kotlin‑lsp` works with opencode.ai on Unix‑like systems, including WSL. I use it on both Linux and macOS with the following setup: 1. Follow the installation instructions at <https://github.com/Kotlin/kotlin-lsp>. 2. Add the following configuration to your `opencode.json`: ```diff { "$schema": "https://opencode.ai/config.json", "provider": { "llama-cpp": { "npm": "@ai-sdk/openai-compatible", "name": "Llama.cpp (local)", "options": { "baseURL": "http://localhost:11434/v1" }, "models": { "gpt-oss-20B": { "name": "unsloth/gpt-oss-20b-GGUF:Q4_K_M" } } } }, "lsp": { + "kotlin-lsp": { + "command": ["kotlin-lsp"], + "extensions": [".kt"] + } } } ```
Author
Owner

@Melodeiro commented on GitHub (Oct 17, 2025):

Hmm, will try. When i tried to specify kotlin-lsp.sh command i got no response. Or maybe due to --stdio parameter...

@Melodeiro commented on GitHub (Oct 17, 2025): Hmm, will try. When i tried to specify kotlin-lsp.sh command i got no response. Or maybe due to --stdio parameter...
Author
Owner

@johannesrave commented on GitHub (Oct 19, 2025):

the lsp generally works but i think opencode hasn't yet implemented pull-style diagnostics. the same was the case for the helix editor (which added support just three weeks ago, the pull-flow appears to be rather new)

@johannesrave commented on GitHub (Oct 19, 2025): the lsp generally works but i think opencode hasn't yet implemented pull-style diagnostics. the same was the case for the helix editor (which added support just three weeks ago, the pull-flow appears to be rather new)
Author
Owner

@pskwr commented on GitHub (Nov 27, 2025):

Has anyone managed to get Kotlin LSP working in opencode?

I tried both:

  • kotlin-lsp
  • fwcd/kotlin-language-server

by configuring them as an lsp in my opencode.json (based on https://opencode.ai/docs/lsp/#custom-lsp-servers), but I couldn’t get either of them to work.

@pskwr commented on GitHub (Nov 27, 2025): Has anyone managed to get Kotlin LSP working in opencode? I tried both: - `kotlin-lsp` - `fwcd/kotlin-language-server` by configuring them as an lsp in my `opencode.json` (based on https://opencode.ai/docs/lsp/#custom-lsp-servers), but I couldn’t get either of them to work.
Author
Owner

@hoota commented on GitHub (Jan 12, 2026):

Any updates on this feature request?
Documentation said kotlin-lsp is now auto installed, but it seems it doesn't work.
At least opencode lsp debug diagnose responses with empty json object - {}

@hoota commented on GitHub (Jan 12, 2026): Any updates on this feature request? Documentation said kotlin-lsp is now auto installed, but it seems it doesn't work. At least opencode lsp debug diagnose responses with empty json object - {}
Author
Owner

@mrclrchtr commented on GitHub (Feb 2, 2026):

how can we check, if it is working as expected?

Edit:
Found the following out with

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

installed https://github.com/Kotlin/kotlin-lsp via brew

Opencode LSP Tool Command Input Type Works? What I observed
Workspace symbol search opencode debug lsp symbols string Partially Command runs, but returns [] for Kotlin queries (TheClass, FQN).
Document symbols opencode debug lsp document-symbols (must be URL) Yes Works with file:///…/TheClass.kt; fails with plain file path (cannot be parsed as a URL). Returns full symbol tree.
Diagnostics opencode debug lsp diagnostics path Yes Works with plain file path; for tested Kotlin file returns {} (no diagnostics surfaced).

BUT: I couldn't get opencode to use the information. It doesn't even notice that kotlin-lsp is there, even though it's displayed in the sidebar:

Image
@mrclrchtr commented on GitHub (Feb 2, 2026): how can we check, if it is working as expected? Edit: Found the following out with ``` "lsp": { "kotlin-ls": { "disabled": true }, "kotlin-lsp": { "command": ["kotlin-lsp", "--stdio"], "extensions": [".kt", ".kts"] } } ``` installed https://github.com/Kotlin/kotlin-lsp via brew | Opencode LSP Tool | Command | Input Type | Works? | What I observed | |----------------------------------|-------------------------------------------|---------------------|-----------|---------------------------------------------------------------------------------------------------------------------| | Workspace symbol search | opencode debug lsp symbols <query> | <query> string | Partially | Command runs, but returns [] for Kotlin queries (TheClass, FQN). | | Document symbols | opencode debug lsp document-symbols <uri> | <uri> (must be URL) | Yes | Works with file:///…/TheClass.kt; fails with plain file path (cannot be parsed as a URL). Returns full symbol tree. | | Diagnostics | opencode debug lsp diagnostics <file> | <file> path | Yes | Works with plain file path; for tested Kotlin file returns {} (no diagnostics surfaced). | BUT: I couldn't get opencode to use the information. It doesn't even notice that kotlin-lsp is there, even though it's displayed in the sidebar: <img width="322" height="240" alt="Image" src="https://github.com/user-attachments/assets/c5b17553-5a82-48d2-9473-55107eed5591" />
Author
Owner

@mrclrchtr commented on GitHub (Feb 2, 2026):

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.

@mrclrchtr commented on GitHub (Feb 2, 2026): 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. ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2061