opencode icon indicating copy to clipboard operation
opencode copied to clipboard

V2: port LSP and formatter services

Open opencode-agent[bot] opened this issue 4 months ago • 13 comments

Summary

Port the LSP and formatter services to the V2 Core/runtime architecture so V2 sessions regain language-server diagnostics and configured formatter behavior without depending on V1 service implementations.

Scope

  • Define V2 service/layer boundaries for LSP and formatter lifecycle.
  • Port configuration resolution and process ownership.
  • Wire file mutations/tool execution to formatting, diagnostics, and relevant client events.
  • Preserve location scoping and clean shutdown/reload behavior.
  • Add focused tests for configuration, startup, formatting, diagnostics, and cleanup.

Context

James announced this implementation work in the V2 coordination thread: https://slack.com/archives/C0BE69AHCQP/p1784822449900729

opencode-agent[bot] avatar Jul 23 '26 16:07 opencode-agent[bot]

Very interested in seeing this, thanks!

As mentioned in my comment on https://github.com/anomalyco/opencode/issues/50916, LSP support (even though it was "just" experimental) was one of the big selling points for us to roll out OpenCode as the standard Agent harness. Being able to use our custom LSP for the in-house framework is an amazing prospect to improve the Agent's work, so we really hope to see support return in V2 soon!

OliverWich avatar Sep 24 '26 09:09 OliverWich

Please support using lsp textDocument/formatting (or textDocument/rangeFormatting to format code ranges , which may be better) instead of using the formatter subprocess mode? (And provide lsp rename/codeAction tools for the agent also a good idea).

zhcn000000 avatar Sep 28 '26 02:09 zhcn000000

@jlongster Is the V2 LSP port actively being worked on? I’d like to contribute. Is there an agreed architecture or a small diagnostics/lifecycle task I could take without duplicating existing work?

AlixANNERAUD avatar Oct 12 '26 11:10 AlixANNERAUD

Supporting this port from the agent-workflow side: while V2 doesn't run language servers, agent sessions fall back to per-repo lint/typecheck commands (cargo check, tsc --noEmit, …) executed through the shell tool. Workable, but it's per-project setup, per-language, and unavailable to sessions that can't shell out.

When the port lands, two things matter for agent reliability:

  1. Diagnostics reach the model (tool result or auto-attached context), not only the TUI — self-correcting on real diagnostics is the biggest quality win for agent-driven edits.
  2. Same lifecycle guarantees as V1: start on matching file open, clean shutdown/reload (avoiding the leak classes already filed, e.g. #50361).

Happy to test the ported service on Windows (v2.0.27) when there's a build. Use case: a Rust desktop app where every agent session currently leans on cargo check for language-level feedback.

smmehdowi avatar Oct 13 '26 04:10 smmehdowi

A key thing i felt was missing from the original LSP implementation was that it only cared about error-level diagnostics with no way to change it. Many language servers use warnings and info for information that OpenCode was dropping on the ground.

https://github.com/anomalyco/opencode/issues/17869#issuecomment-4921195357

parkuman avatar Oct 13 '26 20:10 parkuman

Verification on the published release build (2.0.30): no LSP client present

A user-facing consequence of the missing port is worth measuring precisely, so here is what the shipped CLI contains. Upstream dev still carries packages/opencode/src/lsp/language.ts and packages/opencode/src/lsp/server.ts (visible as changed files on PR #55485, base: dev, created 2026-10-14), so the port looks in flight — but it is not in the published artifact people actually run.

Environment

  • opencode version: v2.0.30 (opencode --version)
  • install/channel: latest, npm package @opencode/[email protected] installed via pnpm global; inspected the real platform binary the launcher execs (a hard link to the pnpm cmd-shim target, ~202 MB, bun compile output)
  • OS: Linux 6.8.0-146-generic, x86_64
  • Shell: /bin/bash, TERM=xterm-256color
  • Active plugins: one git-plugin package (irrelevant to this result)

Method and results

strings -n 6 <binary> dump (439,476 lines), case-sensitive substring counts:

Probe Count
textDocument 0
publishDiagnostics 0
window/workDoneProgress 0
workspace/configuration 0
typescript-language-server 0
pyright-langserver 0
gopls 0
bash-language-server 0
yaml-language-server 0
vscode-langservers-extracted 0

The scan is not blind to embedded JS: ACP method strings are present in the same dump (session/new, session/prompt, fs/read_text_file, document/didOpen, document/didChange, unstable_didOpenDocument), as are chunk paths like /$bunfs/root/chunk-*.js. So the absence of every textDocument/* method name means there is no LSP client in this build, not that the strings were missed.

What does survive is vestigial: lsp.updated remains in the bus/event name list, and Config.LSP.Server / Config.LSP.ServerEncoded remain in the published https://opencode.ai/config.json schema with the description "Enable built-in language servers or configure server overrides".

Why the vestige matters more than the gap

The gap itself is documented — https://opencode.ai/v2/docs/migrate-v1/ states V2 "accepts and preserves lsp configuration, but it does not run language servers, expose LSP tools, or produce LSP diagnostics", and the permissions page says "doom_loop and lsp are not current V2 Core permission actions". Both accurate.

But the config schema advertises lsp as a live field with an actionable description, and the reference is where editors autocomplete from. Someone adding lsp: { … command: [...] } gets schema validation, no warning, no error, and no behavior — and lsp appears in the "common configuration fields" list alongside live fields. When this port lands, consider one of:

  1. dropping or clearly marking the field in config.json until it does something, and/or
  2. logging a one-line warning at config load when lsp is set in a build that will not spawn servers.

Suggested bar for "port landed" (easy to verify from the artifact)

An LSP client must emit textDocument/initialize, textDocument/didOpen, and handle window/workDoneProgress + textDocument/publishDiagnostics. When those strings appear in the shipped binary and the built-in server registry strings come back with them, this issue can be closed against the release. Happy to re-run this exact check on any build you ship.

ahmedelqady avatar Oct 15 '26 21:10 ahmedelqady

Verification on the published release build (2.0.30): no LSP client present

A user-facing consequence of the missing port is worth measuring precisely, so here is what the shipped CLI contains. Upstream dev still carries packages/opencode/src/lsp/language.ts and packages/opencode/src/lsp/server.ts (visible as changed files on PR #55485, base: dev, created 2026-10-14), so the port looks in flight — but it is not in the published artifact people actually run.

Environment

  • opencode version: v2.0.30 (opencode --version)
  • install/channel: latest, npm package @opencode/[email protected] installed via pnpm global; inspected the real platform binary the launcher execs (a hard link to the pnpm cmd-shim target, ~202 MB, bun compile output)
  • OS: Linux 6.8.0-146-generic, x86_64
  • Shell: /bin/bash, TERM=xterm-256color
  • Active plugins: one git-plugin package (irrelevant to this result)

Method and results

strings -n 6 <binary> dump (439,476 lines), case-sensitive substring counts:

Probe Count textDocument 0 publishDiagnostics 0 window/workDoneProgress 0 workspace/configuration 0 typescript-language-server 0 pyright-langserver 0 gopls 0 bash-language-server 0 yaml-language-server 0 vscode-langservers-extracted 0 The scan is not blind to embedded JS: ACP method strings are present in the same dump (session/new, session/prompt, fs/read_text_file, document/didOpen, document/didChange, unstable_didOpenDocument), as are chunk paths like /$bunfs/root/chunk-*.js. So the absence of every textDocument/* method name means there is no LSP client in this build, not that the strings were missed.

What does survive is vestigial: lsp.updated remains in the bus/event name list, and Config.LSP.Server / Config.LSP.ServerEncoded remain in the published https://opencode.ai/config.json schema with the description "Enable built-in language servers or configure server overrides".

Why the vestige matters more than the gap

The gap itself is documented — https://opencode.ai/v2/docs/migrate-v1/ states V2 "accepts and preserves lsp configuration, but it does not run language servers, expose LSP tools, or produce LSP diagnostics", and the permissions page says "doom_loop and lsp are not current V2 Core permission actions". Both accurate.

But the config schema advertises lsp as a live field with an actionable description, and the reference is where editors autocomplete from. Someone adding lsp: { … command: [...] } gets schema validation, no warning, no error, and no behavior — and lsp appears in the "common configuration fields" list alongside live fields. When this port lands, consider one of:

  1. dropping or clearly marking the field in config.json until it does something, and/or
  2. logging a one-line warning at config load when lsp is set in a build that will not spawn servers.

Suggested bar for "port landed" (easy to verify from the artifact)

An LSP client must emit textDocument/initialize, textDocument/didOpen, and handle window/workDoneProgress + textDocument/publishDiagnostics. When those strings appear in the shipped binary and the built-in server registry strings come back with them, this issue can be closed against the release. Happy to re-run this exact check on any build you ship.

@ahmedelqady did you read the issue description? I mean, everybody knows the feature is missing and is going to be ported, no need to have AI slop added into issues with no reason. at least ask the AI to check if it makes sense to post it before posting it.

Idk, I might have become a Karen or smth.

bamancio-futura avatar Oct 16 '26 08:10 bamancio-futura

Cross-ref for this port tracker: I closed two v1 LSP reports today since v1 is gone from dev — #48785 (global LSP activation / NearestRoot gating) and #48787 (first write after cold-start returns no diagnostics). Noting them here so the v2 port can double-check the same two behaviors when it lands.

Bearmancer avatar Oct 18 '26 15:10 Bearmancer

For C# there is a working interim answer that needs no LSP runtime: opencode-roslyn — a plugin tool registered through ctx.tool.transform, driving a standalone Roslyn CLI (roslynq, Roslyn + MSBuildWorkspace). It exposes the same eight operations the V1 lsp tool was given in #51715: structure, types, symbols, members, refs, callers, implementations, rename (dry-run by default).

Symbols are addressed by full name (NextORM.Core.SqlBuilder.MakeSelect), not by file:line:column, so there is no grep step first — which was the point of #51715.

  • npm: opencode-roslyn — published from GitHub Actions through OIDC trusted publishing, with a provenance attestation
  • CLI: dotnet tool install --global opencode-roslyn (nuget.org)
  • source: https://github.com/AlexeyShirshov/skills/tree/main/opencode/plugins/opencode-roslyn

It is deliberately language-specific (C# only) and lives as a plugin rather than in core, so it neither blocks nor duplicates the V2 LSP work: once the ported LSP runtime lands, diagnostics and code actions belong there, and this tool stays the semantic-navigation surface the LSP tool does not cover (references, call hierarchy, rename addressed by name).

Measured on a 20-project solution, honestly: one daemon per solution, ~180 MB after loading, ~730 MB after a few queries; a query takes 8–30 s (the first one loads through MSBuild), and the daemon exits after 10 minutes idle.

AlexeyShirshov avatar Oct 18 '26 17:10 AlexeyShirshov

I'm still staying on v1 due to insufficient migration stability, flaws in some familiar features (todo) and weakened v2 security restrictions, as well as the convenience of running LSP without additional plugins. Daily driver: Python, C#, Windows. With lsp: true the agent gets diagnostics the moment it edits a file; without LSP each change costs an extra lint/typecheck shell round-trip, and the in-the-moment feedback is simply gone.

Coverage that would matter for the port from our side: diagnostics reaching the model (not just the TUI), the lsp tool's symbol operations (#51715), ctx.lsp for plugins (#51416), and reading the v1 lsp config schema — the community plugins (opencode-v2-lsp-support, opencode-roslyn) already prove the demand.

Worth noting the ecosystem keeps converging on the same shape: this week tinyagent shipped opt-in LSP (vicgupta/tinyagent#115), citing opencode v1 and this tracker, with a bounded design that answers the usual concerns directly — off by default, lazy server start, capped diagnostics (count / wait / severity), diagnostics never flipping is_error, and a separate switch for navigation-only. Alongside Claude Code's official LSP plugins and Crush, "configured servers + post-edit diagnostics + symbol navigation" looks like table stakes for agents on typed codebases, not a niche extra.

AlexSilverLight avatar Oct 27 '26 07:10 AlexSilverLight

Confirming the same on the current release, v2.2.6 (Linux x64), from a fresh project config:

  • opencode.jsonc with a custom entry — "lsp": { "lua-ls": { "command": ["lua-language-server"], "extensions": [".lua"] } } — is discovered: opencode debug config lists it, and the schema still accepts it.
  • No lua-language-server process ever starts in a session that reads and edits .lua files, and the log contains no LSP lines at all.
  • "lsp": true (all built-ins) behaves identically, and a brand-new directory/location plus a background service restart change nothing — so it is not stale config or location state.
  • The custom formatter entry in the same file does run (log line formatting file ... stylua on each write/edit), so config resolution and process spawning work for the formatter half.

Net: on 2.2.6 the lsp key is accepted but inert. Keeping the config in place is harmless — it should start working once this lands.

alphabitserial avatar Nov 10 '26 06:11 alphabitserial

@thdxr this is highly needed for instant agent feedback, open since july gang?

iusenvimbtw avatar Nov 12 '26 18:11 iusenvimbtw

+1 from a real-world V2 use case: C# diagnostics via LSP.

Environment: opencode v2.3.0, Windows, .NET Framework 4.8 backend (large solution), SonarLint/SonarQube connected mode.

What we expected: csharp is listed in the built-in LSP table, and we configured lsp.csharp with csharp-ls. In V2 the config is accepted but nothing starts — confirmed in source: packages/core/src/tool/plugin/edit.ts (tag v2.3.0) still carries TODO: Add LSP notification and diagnostics after LSP runtime exists.

Why this matters for us:

  • The agent edits C# files and currently has no in-loop feedback — we fell back to an external csc.exe compile step, which works but loses the "diagnostics injected after edit" UX that made V1's LSP integration valuable.
  • We also tried SonarLint LSP (sonarlint-ls over stdio) with the intent of surfacing SonarQube rules to the agent; without an LSP runtime in the core this bridge has nothing to plug into.

Our concrete ask, in priority order:

  1. Port the V1 LSP runtime (server spawn on extension match + diagnostics into tool results).
  2. A way for plugins to register/observe LSP diagnostics (even read-only), so community bridges (sonarlint, etc.) become possible.

emngny avatar Nov 13 '26 12:11 emngny