Skip to content

Commit 1d74539

Browse files
committed
fix(lsp): resolve concurrent diagnostics waiters
1 parent 9a9b0ac commit 1d74539

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/lsp/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export async function createLSPClient(input: {
8080
diagnostics.set(filePath, diags)
8181

8282
// Notify listeners with debounce
83-
const listener = diagnosticsListeners.find(l => l.path === filePath)
84-
if (listener) {
83+
const listeners = diagnosticsListeners.filter(l => l.path === filePath)
84+
for (const listener of listeners) {
8585
if (listener.timer) { clearTimeout(listener.timer) }
8686
listener.timer = setTimeout(() => {
8787
diagnosticsListeners = diagnosticsListeners.filter(

packages/lsp/test/unit/client.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,28 @@ describe('LSPClient', () => {
167167
expect(client.diagnostics.get(path.normalize(testFile))?.length).toBeGreaterThan(0)
168168
})
169169

170+
test('resolves all diagnostics waiters for the same file', async () => {
171+
const handle = spawnFakePullServer()
172+
173+
client = await createLSPClient({
174+
serverID: 'fake-pull',
175+
server: handle,
176+
root: process.cwd(),
177+
projectPath: process.cwd(),
178+
})
179+
180+
const testFile = path.join(process.cwd(), 'package.json')
181+
const waits = [
182+
client.waitForDiagnostics({ path: testFile }),
183+
client.waitForDiagnostics({ path: testFile }),
184+
]
185+
await client.notify.open({ path: testFile })
186+
187+
const startedAt = performance.now()
188+
await Promise.all(waits)
189+
expect(performance.now() - startedAt).toBeLessThan(1_000)
190+
})
191+
170192
test('opens file with explicit buffer text (no disk read)', async () => {
171193
const handle = spawnFakeServer()
172194

0 commit comments

Comments
 (0)