diff --git a/src/cli/doctor/checks/lsp.test.ts b/src/cli/doctor/checks/lsp.test.ts index b266cc0a6..e21ebc418 100644 --- a/src/cli/doctor/checks/lsp.test.ts +++ b/src/cli/doctor/checks/lsp.test.ts @@ -17,6 +17,21 @@ describe("lsp check", () => { expect(Array.isArray(s.extensions)).toBe(true) }) }) + + it("does not spawn 'which' command (windows compatibility)", async () => { + // #given + const spawnSpy = spyOn(Bun, "spawn") + + // #when getting servers info + await lsp.getLspServersInfo() + + // #then should not spawn which + const calls = spawnSpy.mock.calls + const whichCalls = calls.filter((c) => Array.isArray(c) && Array.isArray(c[0]) && c[0][0] === "which") + expect(whichCalls.length).toBe(0) + + spawnSpy.mockRestore() + }) }) describe("getLspServerStats", () => { diff --git a/src/cli/doctor/checks/lsp.ts b/src/cli/doctor/checks/lsp.ts index 70350edd3..254e3d673 100644 --- a/src/cli/doctor/checks/lsp.ts +++ b/src/cli/doctor/checks/lsp.ts @@ -12,21 +12,13 @@ const DEFAULT_LSP_SERVERS: Array<{ { id: "gopls", binary: "gopls", extensions: [".go"] }, ] -async function checkBinaryExists(binary: string): Promise { - try { - const proc = Bun.spawn(["which", binary], { stdout: "pipe", stderr: "pipe" }) - await proc.exited - return proc.exitCode === 0 - } catch { - return false - } -} +import { isServerInstalled } from "../../../tools/lsp/config" export async function getLspServersInfo(): Promise { const servers: LspServerInfo[] = [] for (const server of DEFAULT_LSP_SERVERS) { - const installed = await checkBinaryExists(server.binary) + const installed = isServerInstalled([server.binary]) servers.push({ id: server.id, installed,