opencode icon indicating copy to clipboard operation
opencode copied to clipboard

How to get opencode to use LSP?

Open nitsanavni opened this issue 5 months ago • 11 comments

I understand there's ootb support for TS and go, but I don't seem to be able to benefit from it.

nitsanavni avatar Jul 05 '25 12:07 nitsanavni

the way it works is when edit calls are made and it introduces an error we send those errors back to the LLM

if you suspect it's not working you can try the following command opencode debug lsp diagnostics ./path/to/file/with/error.ts

thdxr avatar Jul 05 '25 14:07 thdxr

No additional configuration for LSP support (as described here https://pkg.go.dev/github.com/sst/opencode#readme-lsp-language-server-protocol) is required?

olk avatar Jul 13 '25 18:07 olk

Bumping this question ^ I'd like to hook in a custom LSP (Lexical for Elixir), and it seems the lsp key is not accepted in opencode.json. Maybe this feature is in flux?

giddie avatar Jul 18 '25 10:07 giddie

No additional configuration for LSP support (as described here https://pkg.go.dev/github.com/sst/opencode#readme-lsp-language-server-protocol) is required?

this is the other opencode; @thdxr will add custom lsp config soon

adamdotdevin avatar Jul 18 '25 11:07 adamdotdevin

Just FYI, the docs I found were linked from this repo. It popped up when I searched for LSP: https://opencode.ai/docs/lsp-servers

Since it's not linked in the menu, I figured it probably was something still being worked on. You're doing great work guys; thanks so much.

giddie avatar Jul 18 '25 14:07 giddie

Just FYI, the docs I found were linked from this repo. It popped up when I searched for LSP: https://opencode.ai/docs/lsp-servers

Since it's not linked in the menu, I figured it probably was something still being worked on. You're doing great work guys; thanks so much.

That was irritating me too ... the linked documentation does not fit to the sst/opencode source. for instance the documentation refers to ~/.config/opencode/opencode.json as config file which is wrong for the sst/opencode (it is ~/.config/opencode/config.json).

olk avatar Jul 18 '25 14:07 olk

This is not working for me. I do the following:

  1. Ask Claude Sonnet 4 to deliberately edit a file and introduce an error.
  2. It does this and tells me that it is not being passed any lsp diagnostics
  3. I open the file in NeoVim and confirm that Claude has indeed added an error, which is being highlighted as such by the typescript lsp running in NeoVim
  4. I run opencode debug lsp diagnostics ./path/to/file/with/error.ts and get the output below, which looks fine to me:

opencode debug lsp diagnostics ./src/config/config.ts { "/home/david/projects/grace/packages/grace-core/src/config/config.ts": [ { range: [Object ...], message: "Type 'number' is not assignable to type 'string'.", severity: 1, code: 2322, source: "typescript", }, { range: [Object ...], message: "'z' is declared but its value is never read.", severity: 4, code: 6133, source: "typescript", }, { range: [Object ...], message: "'invalidCode' is declared but its value is never read.", severity: 4, code: 6133, source: "typescript", } ], }

davidfriar1 avatar Jul 19 '25 15:07 davidfriar1

This is not working for me. I do the following:

  1. Ask Claude Sonnet 4 to deliberately edit a file and introduce an error.
  2. It does this and tells me that it is not being passed any lsp diagnostics
  3. I open the file in NeoVim and confirm that Claude has indeed added an error, which is being highlighted as such by the typescript lsp running in NeoVim
  4. I run opencode debug lsp diagnostics ./path/to/file/with/error.ts and get the output below, which looks fine to me:

opencode debug lsp diagnostics ./src/config/config.ts { "/home/david/projects/grace/packages/grace-core/src/config/config.ts": [ { range: [Object ...], message: "Type 'number' is not assignable to type 'string'.", severity: 1, code: 2322, source: "typescript", }, { range: [Object ...], message: "'z' is declared but its value is never read.", severity: 4, code: 6133, source: "typescript", }, { range: [Object ...], message: "'invalidCode' is declared but its value is never read.", severity: 4, code: 6133, source: "typescript", } ], }

Same. It's wried that when I run opencode debug lsp diagnostics <file path> it got me the issues I'm expecting, but when I use the program and even explicitly ask about any issues on that file using LSP, it doesn't report anything that is reported from the debug lsp command. Instead, it fallbacks to run tsc --noEmit ... command.

@thdxr any clue?

alvis avatar Aug 09 '25 11:08 alvis

I tried this on the Pet.java file, which has a syntax error:

 > opencode debug lsp diagnostics ./src/main/java/org/springframework/samples/petclinic/owner/Pet.java
{}

The result is an empty json?

jgordijn-ah avatar Dec 20 '25 10:12 jgordijn-ah

the way it works is when edit calls are made and it introduces an error we send those errors back to the LLMif you suspect it's not working you can try the following command opencode debug lsp diagnostics ./path/to/file/with/error.ts

Just curious how its different from calling tsc or any other cli tool to get errors? The issue is performance? You dont need to build go project for example, etc

istarkov avatar Dec 21 '25 06:12 istarkov