fix(lsp): cancel blocked document opens

This commit is contained in:
Tianyi Cui
2026-07-21 13:52:15 +08:00
parent 2fd995bf3c
commit bc60b9ffe8
7 changed files with 82 additions and 12 deletions

View File

@@ -138,9 +138,16 @@ export class LspInstance {
try {
/* v8 ignore next -- guards an abort landing between the ready wait and didOpen; not deterministically reproducible. */
if (signal?.aborted) throw abortError(signal)
await this.connection.notify('textDocument/didOpen', {
textDocument: { uri, languageId: request.languageId, version: 1, text: source.text },
})
try {
await abortable(this.connection.notify('textDocument/didOpen', {
textDocument: { uri, languageId: request.languageId, version: 1, text: source.text },
}), signal)
} catch (error) {
// A canceled backpressured write or failed stdin leaves the protocol stream unusable before
// `opened` can arm the didClose cleanup. Teardown here makes the pool evict the instance.
await this.startTeardown()
throw error
}
opened = true
const payload = await this.sendRequest(request.operation, uri, request.position, signal)
return this.normalize(request.operation, payload)