From 613b5fbe4814397e8e874fa24a3c98f4e3ce2e4f Mon Sep 17 00:00:00 2001 From: Yihui Khuu Date: Sat, 26 Jul 2025 02:17:06 +1000 Subject: [PATCH] feat: add csharp lsp (#1312) --- packages/opencode/src/lsp/server.ts | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/opencode/src/lsp/server.ts b/packages/opencode/src/lsp/server.ts index 8c843fea..f4648f0c 100644 --- a/packages/opencode/src/lsp/server.ts +++ b/packages/opencode/src/lsp/server.ts @@ -322,4 +322,43 @@ export namespace LSPServer { } }, } + + export const CSharp: Info = { + id: "csharp", + root: NearestRoot([".sln", ".csproj", "global.json"]), + extensions: [".cs"], + async spawn(_, root) { + let bin = Bun.which("csharp-ls", { + PATH: process.env["PATH"] + ":" + Global.Path.bin, + }) + if (!bin) { + if (!Bun.which("dotnet")) { + log.error(".NET SDK is required to install csharp-ls") + return + } + + log.info("installing csharp-ls via dotnet tool") + const proc = Bun.spawn({ + cmd: ["dotnet", "tool", "install", "csharp-ls", "--tool-path", Global.Path.bin], + stdout: "pipe", + stderr: "pipe", + stdin: "pipe", + }) + const exit = await proc.exited + if (exit !== 0) { + log.error("Failed to install csharp-ls") + return + } + + bin = path.join(Global.Path.bin, "csharp-ls" + (process.platform === "win32" ? ".exe" : "")) + log.info(`installed csharp-ls`, { bin }) + } + + return { + process: spawn(bin, { + cwd: root, + }), + } + }, + } }