add typescript lsp timeout if it fails to start

This commit is contained in:
Dax Raad 2025-07-08 18:33:12 -04:00
parent 4a878b88c0
commit 00ea5082e7
2 changed files with 7 additions and 2 deletions

View file

@ -53,7 +53,10 @@ export namespace LSP {
serverID: server.id,
server: handle,
root,
}).catch((err) => log.error("", { error: err }))
}).catch((err) => {
handle.process.kill()
log.error("", { error: err })
})
if (!client) break
clients.push(client)
}

View file

@ -9,6 +9,7 @@ import fs from "fs/promises"
import { unique } from "remeda"
import { Ripgrep } from "../file/ripgrep"
import type { LSPClient } from "./client"
import { withTimeout } from "../util/timeout"
export namespace LSPServer {
const log = Log.create({ service: "lsp.server" })
@ -69,7 +70,7 @@ export namespace LSPServer {
glob: ["*.ts", "*.tsx", "*.js", "*.jsx", "*.mjs", "*.cjs", "*.mts", "*.cts"],
limit: 1,
})
await new Promise<void>(async (resolve) => {
const wait = new Promise<void>(async (resolve) => {
const notif = lsp.connection.onNotification("$/progress", (params) => {
if (params.value.kind !== "end") return
notif.dispose()
@ -77,6 +78,7 @@ export namespace LSPServer {
})
await lsp.notify.open({ path: path.join(lsp.root, hint) })
})
await withTimeout(wait, 5_000)
},
}
},