fix(cli): avoid unix which in lsp doctor check

This commit is contained in:
MotorwaySouth9
2026-01-16 08:40:37 +08:00
parent f9b9b59658
commit ca2f8059a6
2 changed files with 17 additions and 10 deletions

View File

@@ -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", () => {

View File

@@ -12,21 +12,13 @@ const DEFAULT_LSP_SERVERS: Array<{
{ id: "gopls", binary: "gopls", extensions: [".go"] },
]
async function checkBinaryExists(binary: string): Promise<boolean> {
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<LspServerInfo[]> {
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,