fix(cli): avoid unix which in lsp doctor check
This commit is contained in:
parent
f9b9b59658
commit
ca2f8059a6
@ -17,6 +17,21 @@ describe("lsp check", () => {
|
|||||||
expect(Array.isArray(s.extensions)).toBe(true)
|
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", () => {
|
describe("getLspServerStats", () => {
|
||||||
|
|||||||
@ -12,21 +12,13 @@ const DEFAULT_LSP_SERVERS: Array<{
|
|||||||
{ id: "gopls", binary: "gopls", extensions: [".go"] },
|
{ id: "gopls", binary: "gopls", extensions: [".go"] },
|
||||||
]
|
]
|
||||||
|
|
||||||
async function checkBinaryExists(binary: string): Promise<boolean> {
|
import { isServerInstalled } from "../../../tools/lsp/config"
|
||||||
try {
|
|
||||||
const proc = Bun.spawn(["which", binary], { stdout: "pipe", stderr: "pipe" })
|
|
||||||
await proc.exited
|
|
||||||
return proc.exitCode === 0
|
|
||||||
} catch {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getLspServersInfo(): Promise<LspServerInfo[]> {
|
export async function getLspServersInfo(): Promise<LspServerInfo[]> {
|
||||||
const servers: LspServerInfo[] = []
|
const servers: LspServerInfo[] = []
|
||||||
|
|
||||||
for (const server of DEFAULT_LSP_SERVERS) {
|
for (const server of DEFAULT_LSP_SERVERS) {
|
||||||
const installed = await checkBinaryExists(server.binary)
|
const installed = isServerInstalled([server.binary])
|
||||||
servers.push({
|
servers.push({
|
||||||
id: server.id,
|
id: server.id,
|
||||||
installed,
|
installed,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user