Skip to content

Commit d1b6c63

Browse files
Honavaur94
authored andcommitted
feat: support pull diagnostics in the LSP client (C#, Kotlin, etc) (anomalyco#23771)
(cherry picked from commit e383df4)
1 parent d13abcb commit d1b6c63

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

packages/opencode/src/lsp/client.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ export async function create(input: { serverID: string; server: LSPServer.Handle
358358
return { handled, matched, byFile }
359359
}
360360

361-
async function requestWorkspaceDiagnosticReport(
362-
filePath: string,
363-
identifier?: string,
364-
): Promise<DiagnosticRequestResult> {
361+
async function requestWorkspaceDiagnosticReport(filePath: string, identifier?: string): Promise<DiagnosticRequestResult> {
365362
const report = await withTimeout(
366363
connection.sendRequest<WorkspaceDiagnosticReport | null>("workspace/diagnostic", {
367364
...(identifier ? { identifier } : {}),
@@ -389,9 +386,7 @@ export async function create(input: { serverID: string; server: LSPServer.Handle
389386
(registration) => registration.registerOptions?.workspaceDiagnostics !== true,
390387
)
391388
return {
392-
documentIdentifiers: [
393-
...new Set(documentRegistrations.flatMap((registration) => registration.registerOptions?.identifier ?? [])),
394-
],
389+
documentIdentifiers: [...new Set(documentRegistrations.flatMap((registration) => registration.registerOptions?.identifier ?? []))],
395390
supported: hasStaticPullDiagnostics || documentRegistrations.length > 0,
396391
}
397392
}
@@ -401,9 +396,7 @@ export async function create(input: { serverID: string; server: LSPServer.Handle
401396
(registration) => registration.registerOptions?.workspaceDiagnostics === true,
402397
)
403398
return {
404-
workspaceIdentifiers: [
405-
...new Set(workspaceRegistrations.flatMap((registration) => registration.registerOptions?.identifier ?? [])),
406-
],
399+
workspaceIdentifiers: [...new Set(workspaceRegistrations.flatMap((registration) => registration.registerOptions?.identifier ?? []))],
407400
supported: workspaceRegistrations.length > 0,
408401
}
409402
}
@@ -468,9 +461,7 @@ export async function create(input: { serverID: string; server: LSPServer.Handle
468461
...(documentState.supported ? [requestDiagnosticReport(filePath)] : []),
469462
...documentState.documentIdentifiers.map((identifier) => requestDiagnosticReport(filePath, identifier)),
470463
...(workspaceState.supported ? [requestWorkspaceDiagnosticReport(filePath)] : []),
471-
...workspaceState.workspaceIdentifiers.map((identifier) =>
472-
requestWorkspaceDiagnosticReport(filePath, identifier),
473-
),
464+
...workspaceState.workspaceIdentifiers.map((identifier) => requestWorkspaceDiagnosticReport(filePath, identifier)),
474465
]),
475466
)
476467
}
@@ -541,8 +532,8 @@ export async function create(input: { serverID: string; server: LSPServer.Handle
541532
const remaining = DIAGNOSTICS_DOCUMENT_WAIT_TIMEOUT_MS - (Date.now() - startedAt)
542533
if (remaining <= 0) return
543534
const next = await Promise.race([
544-
pushWait.then((ready) => (ready ? "push" : ("timeout" as const))),
545-
waitForRegistrationChange(remaining).then((changed) => (changed ? "registration" : ("timeout" as const))),
535+
pushWait.then((ready) => (ready ? "push" : "timeout" as const)),
536+
waitForRegistrationChange(remaining).then((changed) => (changed ? "registration" : "timeout" as const)),
546537
])
547538
if (next !== "registration") return
548539
}
@@ -563,8 +554,8 @@ export async function create(input: { serverID: string; server: LSPServer.Handle
563554
const remaining = DIAGNOSTICS_FULL_WAIT_TIMEOUT_MS - (Date.now() - startedAt)
564555
if (remaining <= 0) return
565556
const next = await Promise.race([
566-
pushWait.then((ready) => (ready ? "push" : ("timeout" as const))),
567-
waitForRegistrationChange(remaining).then((changed) => (changed ? "registration" : ("timeout" as const))),
557+
pushWait.then((ready) => (ready ? "push" : "timeout" as const)),
558+
waitForRegistrationChange(remaining).then((changed) => (changed ? "registration" : "timeout" as const)),
568559
])
569560
if (next !== "registration") return
570561
}

0 commit comments

Comments
 (0)