Skip to content

Add diagnostic API methods#3234

Open
Copilot wants to merge 10 commits intomainfrom
copilot/add-api-methods-for-diagnostics
Open

Add diagnostic API methods#3234
Copilot wants to merge 10 commits intomainfrom
copilot/add-api-methods-for-diagnostics

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Adds getSyntacticDiagnostics, getSemanticDiagnostics, getSuggestionDiagnostics, getConfigFileParsingDiagnostics, and getDeclarationDiagnostics to the API surface.

Diagnostic API

  • New method constants, proto params, and session handlers for each diagnostic kind
  • Async Program methods that call through to the Go server, plus auto-generated sync variants
  • Response type is Diagnostic directly (no intermediate wire type needed since the shapes are identical at runtime)
  • reportsUnnecessary/reportsDeprecated use omitzero so false is omitted from JSON and the TS types remain optional booleans — only true is sent on the wire
  • getGlobalDiagnostics is excluded for now due to a pre-existing checker pool type assertion issue in the compiler

Test helper: rangeOf

Tests use assert.deepEqual with exact expected values. A rangeOf(source, searchString, occurrence?) helper computes { pos, end } via indexOf, replacing opaque magic numbers with human-readable assertions:

const source = `interface Props { callback: (x: string) => void }
const p: Props = { callback: (x: number) => {} };`;

const declRange = rangeOf(source, "callback", 0);   // declaration site
const assignRange = rangeOf(source, "callback", 1);  // assignment site

assert.deepEqual(diags, [{
    fileName: "/src/index.ts",
    ...assignRange,
    code: 2322,
    category: DiagnosticCategory.Error,
    text: "Type '(x: number) => void' is not assignable to type '(x: string) => void'.",
    relatedInformation: [{ ...declRange, /* ... */ }],
}]);

occurrence is 0-based (default 0). One test per diagnostic method; the semantic test covers both messageChain and relatedInformation.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 6 commits March 25, 2026 18:03
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/6f3e15a9-c839-4abd-9dcf-00432f1530bf
@andrewbranch andrewbranch changed the title Add diagnostic API methods with rangeOf test helper for readable assertions Add diagnostic API methods Mar 26, 2026
…ponse type

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/ab4f4d56-a31a-4512-88a1-b261f1b0d1a2
Copilot AI requested a review from andrewbranch March 26, 2026 01:14
@andrewbranch andrewbranch marked this pull request as ready for review March 26, 2026 15:07
Copilot AI review requested due to automatic review settings March 26, 2026 15:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds compiler diagnostic retrieval to the TypeScript-Go API surface, wiring new request methods through the Go session layer and exposing them via the @typescript/api Program (async + generated sync). Also introduces a small test helper to make diagnostic range assertions easier to read.

Changes:

  • Add new diagnostic API methods (syntactic/semantic/suggestion/declaration/config parsing/global) to internal/api protocol + session handlers.
  • Expose the new methods on _packages/api Program and add Diagnostic + DiagnosticCategory types.
  • Add sync/async API tests for each diagnostic method and a rangeOf helper for { pos, end } assertions.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/api/session.go Adds request routing + handlers that call program.Get*Diagnostics(...), including optional-file resolution.
internal/api/proto.go Adds method constants, params structs, and diagnostic response serialization (DiagnosticResponse).
_packages/api/src/async/api.ts Adds async Program.get*Diagnostics methods and re-exports DiagnosticCategory.
_packages/api/src/async/types.ts Introduces Diagnostic interface and imports DiagnosticCategory type.
_packages/api/src/sync/api.ts Generated sync counterparts of the new Program.get*Diagnostics methods and exports.
_packages/api/src/sync/types.ts Generated sync Diagnostic interface.
_packages/api/src/enums/diagnosticCategory.ts Adds runtime enum module for DiagnosticCategory (generated).
_packages/api/src/enums/diagnosticCategory.enum.ts Adds type enum module for DiagnosticCategory (generated).
_packages/api/test/async/api.test.ts Adds async coverage for each diagnostics method + rangeOf helper.
_packages/api/test/sync/api.test.ts Adds sync coverage for each diagnostics method + rangeOf helper.
Herebyfile.mjs Registers DiagnosticCategory for enum generation into _packages/api/src/enums.

@andrewbranch
Copy link
Copy Markdown
Member

@copilot address review feedback and format

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 26, 2026

@copilot address review feedback and format

Removed omitempty from reportsUnnecessary/reportsDeprecated so false is always serialized, and ran the formatter. Fixed in e28d9f9.

Note: I kept the getGlobalDiagnostics test as a type check only because GetGlobalDiagnostics in internal/compiler/program.go:1164 does a hard type assertion p.checkerPool.(*checkerPool) that panics when the API uses the project-level checker pool. That's a pre-existing bug unrelated to this PR.

@andrewbranch
Copy link
Copy Markdown
Member

@copilot just remove getGlobalDiagnostics from the API for now.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/d4721030-7ecc-47da-af0e-b0c054c3fca3

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 26, 2026

@copilot just remove getGlobalDiagnostics from the API for now.

Removed getGlobalDiagnostics from the Go protocol, session handler, and TypeScript Program class, along with its tests in both async and sync suites. Fixed in ab2d911.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@andrewbranch andrewbranch enabled auto-merge March 27, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants