C# language server (csharp-ls) doesn't work #1228

Open
opened 2026-02-16 17:30:05 -05:00 by yindo · 5 comments
Owner

Originally created by @asaf92 on GitHub (Aug 11, 2025).

Originally assigned to: @thdxr on GitHub.

Even when I create toy examples, the C# language server does not seem to work.

I have dotnet SDK installed with csharp-ls:

ls-test-cs  > dotnet --version
9.0.203
ls-test-cs  > dotnet tool list --global |grep csharp
csharp-ls            0.18.0       csharp-ls   

Create a new project (does not matter if there's a solution or not, it doesn't work regardless:

ls-test-cs  > dotnet new sln -n MySolution && \
dotnet new web -n MyProject && \
dotnet sln MySolution.sln add MyProject

The template "Solution File" was created successfully.

The template "ASP.NET Core Empty" was created successfully.

Processing post-creation actions...
Restoring /tmp/ls-test-cs/MyProject/MyProject.csproj:
Restore succeeded.


Project `MyProject/MyProject.csproj` added to the solution.
ls-test-cs  > dotnet build
Restore complete (0.6s)
  MyProject succeeded (2.3s) → MyProject/bin/Debug/net9.0/MyProject.dll

Build succeeded in 3.1s

I edit the file to trigger a diagnostic:

ls-test-cs  > cat ./MyProject/Program.cs 
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

int x = "432"; // Error - Cannot implicitly convert type 'string' to 'int'
app.MapGet("/", () => "Hello World!");

app.Run();

And neither the agent nor the opencode debug lsp commands indicate that it works. Here's the debug output with logs:

ls-test-cs  > opencode debug lsp diagnostics --print-logs ./MyProject/Program.cs
INFO  2025-08-11T08:47:47 +112ms service=default version=0.4.2 args=["debug","lsp","diagnostics","--print-logs","./MyProject/Program.cs"] opencode
INFO  2025-08-11T08:47:47 +1ms service=app cwd=/tmp/ls-test-cs creating
INFO  2025-08-11T08:47:47 +1ms service=app git
INFO  2025-08-11T08:47:47 +1ms service=bus type=storage.write subscribing
INFO  2025-08-11T08:47:47 +0ms service=app name=bus registering service
INFO  2025-08-11T08:47:47 +0ms service=format init
INFO  2025-08-11T08:47:47 +0ms service=bus type=file.edited subscribing
INFO  2025-08-11T08:47:47 +0ms service=bus type=* subscribing
INFO  2025-08-11T08:47:47 +0ms service=config.hooks init
INFO  2025-08-11T08:47:47 +0ms service=bus type=file.edited subscribing
INFO  2025-08-11T08:47:47 +0ms service=bus type=session.idle subscribing
INFO  2025-08-11T08:47:47 +0ms service=app name=lsp registering service
INFO  2025-08-11T08:47:47 +0ms service=app name=config registering service
INFO  2025-08-11T08:47:47 +2ms service=config path=/home/aagami/.config/opencode/config.json loading
INFO  2025-08-11T08:47:47 +3ms service=config path=/home/aagami/.config/opencode/opencode.json loading
INFO  2025-08-11T08:47:47 +0ms service=config path=/home/aagami/.config/opencode/opencode.jsonc loading
INFO  2025-08-11T08:47:47 +2ms service=config agent={} mode={} plugin=[] username=aagami loaded
INFO  2025-08-11T08:47:47 +3ms service=lsp.client serverID=csharp starting client
INFO  2025-08-11T08:47:47 +1ms service=lsp.client serverID=csharp sending initialize
INFO  2025-08-11T08:47:47 +609ms service=lsp.client serverID=csharp initialized
INFO  2025-08-11T08:47:47 +1ms service=lsp.client serverID=csharp path=/tmp/ls-test-cs/MyProject/Program.cs waiting for diagnostics
INFO  2025-08-11T08:47:47 +0ms service=bus type=lsp.client.diagnostics subscribing
INFO  2025-08-11T08:47:47 +0ms service=lsp.client serverID=csharp path=/tmp/ls-test-cs/MyProject/Program.cs textDocument/didOpen
INFO  2025-08-11T08:47:47 +279ms service=lsp.client serverID=csharp token=e507a269-0eae-405c-b1ed-0c382c57cdd9 window/workDoneProgress/create
INFO  2025-08-11T08:47:50 +2723ms service=bus type=lsp.client.diagnostics unsubscribing
{}
INFO  2025-08-11T08:47:50 +1ms service=app name=lsp shutdown
INFO  2025-08-11T08:47:50 +0ms service=lsp.client serverID=csharp shutting down
INFO  2025-08-11T08:47:50 +1ms service=lsp.client serverID=csharp shutdown

I'm using Ubuntu. I tested typescript and it worked fine (I could see diagnostics with opencode debug lsp diagnostics)

Originally created by @asaf92 on GitHub (Aug 11, 2025). Originally assigned to: @thdxr on GitHub. Even when I create toy examples, the C# language server does not seem to work. I have dotnet SDK installed with csharp-ls: ``` ls-test-cs > dotnet --version 9.0.203 ls-test-cs > dotnet tool list --global |grep csharp csharp-ls 0.18.0 csharp-ls ``` Create a new project (does not matter if there's a solution or not, it doesn't work regardless: ``` ls-test-cs > dotnet new sln -n MySolution && \ dotnet new web -n MyProject && \ dotnet sln MySolution.sln add MyProject The template "Solution File" was created successfully. The template "ASP.NET Core Empty" was created successfully. Processing post-creation actions... Restoring /tmp/ls-test-cs/MyProject/MyProject.csproj: Restore succeeded. Project `MyProject/MyProject.csproj` added to the solution. ls-test-cs > dotnet build Restore complete (0.6s) MyProject succeeded (2.3s) → MyProject/bin/Debug/net9.0/MyProject.dll Build succeeded in 3.1s ``` I edit the file to trigger a diagnostic: ``` ls-test-cs > cat ./MyProject/Program.cs var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); int x = "432"; // Error - Cannot implicitly convert type 'string' to 'int' app.MapGet("/", () => "Hello World!"); app.Run(); ``` And neither the agent nor the `opencode debug lsp` commands indicate that it works. Here's the debug output with logs: ``` ls-test-cs > opencode debug lsp diagnostics --print-logs ./MyProject/Program.cs INFO 2025-08-11T08:47:47 +112ms service=default version=0.4.2 args=["debug","lsp","diagnostics","--print-logs","./MyProject/Program.cs"] opencode INFO 2025-08-11T08:47:47 +1ms service=app cwd=/tmp/ls-test-cs creating INFO 2025-08-11T08:47:47 +1ms service=app git INFO 2025-08-11T08:47:47 +1ms service=bus type=storage.write subscribing INFO 2025-08-11T08:47:47 +0ms service=app name=bus registering service INFO 2025-08-11T08:47:47 +0ms service=format init INFO 2025-08-11T08:47:47 +0ms service=bus type=file.edited subscribing INFO 2025-08-11T08:47:47 +0ms service=bus type=* subscribing INFO 2025-08-11T08:47:47 +0ms service=config.hooks init INFO 2025-08-11T08:47:47 +0ms service=bus type=file.edited subscribing INFO 2025-08-11T08:47:47 +0ms service=bus type=session.idle subscribing INFO 2025-08-11T08:47:47 +0ms service=app name=lsp registering service INFO 2025-08-11T08:47:47 +0ms service=app name=config registering service INFO 2025-08-11T08:47:47 +2ms service=config path=/home/aagami/.config/opencode/config.json loading INFO 2025-08-11T08:47:47 +3ms service=config path=/home/aagami/.config/opencode/opencode.json loading INFO 2025-08-11T08:47:47 +0ms service=config path=/home/aagami/.config/opencode/opencode.jsonc loading INFO 2025-08-11T08:47:47 +2ms service=config agent={} mode={} plugin=[] username=aagami loaded INFO 2025-08-11T08:47:47 +3ms service=lsp.client serverID=csharp starting client INFO 2025-08-11T08:47:47 +1ms service=lsp.client serverID=csharp sending initialize INFO 2025-08-11T08:47:47 +609ms service=lsp.client serverID=csharp initialized INFO 2025-08-11T08:47:47 +1ms service=lsp.client serverID=csharp path=/tmp/ls-test-cs/MyProject/Program.cs waiting for diagnostics INFO 2025-08-11T08:47:47 +0ms service=bus type=lsp.client.diagnostics subscribing INFO 2025-08-11T08:47:47 +0ms service=lsp.client serverID=csharp path=/tmp/ls-test-cs/MyProject/Program.cs textDocument/didOpen INFO 2025-08-11T08:47:47 +279ms service=lsp.client serverID=csharp token=e507a269-0eae-405c-b1ed-0c382c57cdd9 window/workDoneProgress/create INFO 2025-08-11T08:47:50 +2723ms service=bus type=lsp.client.diagnostics unsubscribing {} INFO 2025-08-11T08:47:50 +1ms service=app name=lsp shutdown INFO 2025-08-11T08:47:50 +0ms service=lsp.client serverID=csharp shutting down INFO 2025-08-11T08:47:50 +1ms service=lsp.client serverID=csharp shutdown ``` I'm using Ubuntu. I tested typescript and it worked fine (I could see diagnostics with `opencode debug lsp diagnostics`)
Author
Owner

@P-de-Jong commented on GitHub (Aug 13, 2025):

I opened a PR to fix this, but it's still not 100% perfect.

  • Doesn't work well with mono repo situations.
  • Only works with .NET 9 or higher, since csharp-ls requires it
  • I get some weird false positives sometimes:
Image

Its one of the reasons i opened this PR before for the VSCode extension: https://github.com/sst/opencode/pull/1367
It allows me to send diagnostics from the LSP in VSCode to Opencode.

@thdxr I would love to add more functionality to the VSCode extension for sending diagnostics straight from VSCode to Opencode, but don't know if these PR's get accepted in the first place. Any thoughts?

@P-de-Jong commented on GitHub (Aug 13, 2025): I opened a PR to fix this, but it's still not 100% perfect. - Doesn't work well with mono repo situations. - Only works with .NET 9 or higher, since csharp-ls requires it - I get some weird false positives sometimes: <img width="759" height="468" alt="Image" src="https://github.com/user-attachments/assets/c000d888-436c-46d6-8710-6d5d76dc7310" /> Its one of the reasons i opened this PR before for the VSCode extension: https://github.com/sst/opencode/pull/1367 It allows me to send diagnostics from the LSP in VSCode to Opencode. @thdxr I would love to add more functionality to the VSCode extension for sending diagnostics straight from VSCode to Opencode, but don't know if these PR's get accepted in the first place. Any thoughts?
Author
Owner

@asaf92 commented on GitHub (Aug 17, 2025):

ok so this is strange, I'm running opencode 0.5.5 and it seems to work:

Image

It doesn't work with the debug command, still returns an empty {}

@asaf92 commented on GitHub (Aug 17, 2025): ok so this is strange, I'm running opencode 0.5.5 and it seems to work: <img width="1184" height="689" alt="Image" src="https://github.com/user-attachments/assets/308cf437-b98e-4224-9475-1144fb0ecc63" /> It doesn't work with the debug command, still returns an empty `{}`
Author
Owner

@P-de-Jong commented on GitHub (Aug 26, 2025):

@asaf92 i get mixed results in our mono repo, depending on where i start opencode and where the files are.

@P-de-Jong commented on GitHub (Aug 26, 2025): @asaf92 i get mixed results in our mono repo, depending on where i start opencode and where the files are.
Author
Owner

@asaf92 commented on GitHub (Aug 26, 2025):

@P-de-Jong maybe it's due to timeouts? the C# LS can be slow and I understand opencode has some aggressive timeout that's not configurable (at least last time I checked)

@asaf92 commented on GitHub (Aug 26, 2025): @P-de-Jong maybe it's due to timeouts? the C# LS can be slow and I understand opencode has some aggressive timeout that's not configurable (at least last time I checked)
Author
Owner

@P-de-Jong commented on GitHub (Aug 27, 2025):

@asaf92 in the meantime i created my own VSCode extension to get relevant context from there, this seems to work for my situation with multiple vscodes open in a monorepo 🤷‍♂️

https://marketplace.visualstudio.com/items?itemName=pimdejong.codebridge-mcp

It allows to retrieve context from open files, selected text and LSP's from VSCode.

@thdxr it would be nice to have this kind of functionality in the official extension :)

@P-de-Jong commented on GitHub (Aug 27, 2025): @asaf92 in the meantime i created my own VSCode extension to get relevant context from there, this seems to work for my situation with multiple vscodes open in a monorepo 🤷‍♂️ https://marketplace.visualstudio.com/items?itemName=pimdejong.codebridge-mcp It allows to retrieve context from open files, selected text and LSP's from VSCode. @thdxr it would be nice to have this kind of functionality in the official extension :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1228