Skip to content

feat(content-mapper): add diagnostic-code selectors - #65517

Open
ubugeeei (ubugeeei) wants to merge 2 commits into
microsoft:mainfrom
ubugeeei:feat/content-mapper-diagnostic-code-selectors
Open

ubugeeei (ubugeeei) wants to merge 2 commits into
microsoft:mainfrom
ubugeeei:feat/content-mapper-diagnostic-code-selectors

Conversation

@ubugeeei

@ubugeeei ubugeeei (ubugeeei) commented Nov 15, 2026 •

Copy link
Copy Markdown

Fixes #65516

Related producer work: ubugeeei-prod/vize#13065 (tracked by ubugeeei-prod/vize#13057)

Summary

  • advertise diagnosticDirectiveCodeSelectors in content-mapper initialize capabilities
  • decode the optional sixth ignore-tuple element as a TypeScript diagnostic code
  • suppress a diagnostic only when both its virtual range and code match
  • carry the selector through the Go and Node API binary packet at protocol version 10
  • report invalid selectors with localized diagnostic 18142 and the directive index

Compatibility

Legacy five-element ignore tuples and all expect tuples keep their existing content-mapper encoding and behavior. A mapper only emits the selected form after the host advertises support, so an older host never falls back to range-only suppression.

The internal API packet changes from a six-field directive record to a seven-field record and bumps the binary protocol version from 9 to 10, keeping its encoder and decoder in lockstep.

Validation

  • protocol round-trip coverage for legacy, expect, and selected ignore tuples
  • host normalization and invalid-code coverage
  • compiler coverage proving TS2353 is filtered while TS2322 in the same selected range remains
  • byte-level Go API encoder coverage and TypeScript API decoder coverage for the selector
  • localized transform-error coverage for the invalid-selector code and message
  • GitHub Actions is the validation authority for format, lint, and tests

Co-authored-by: miyaoka <1443118+miyaoka@users.noreply.github.com>
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 15, 2026
@ubugeeei
ubugeeei (ubugeeei) marked this pull request as ready for review November 15, 2026 16:33
Copilot AI balanced review requested due to automatic review settings November 15, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

API construction and encoding omit diagnosticCode, causing a TypeScript type-checking error and preventing selectors from reaching clients, while invalid selectors produce only a generic error without the rejection reason or directive index.

2 open issues
What changed in this PR

Adds diagnostic-code selectors to content-mapper ignore directives for #65516, allowing targeted suppression without hiding unrelated diagnostics in the same generated range.

Changes:

  • Advertises selector support and decodes an optional sixth ignore-tuple element while preserving legacy ignore and expect encodings.
  • Filters diagnostics by both range and code, with selector fields added to the Go and TypeScript AST mirrors.
  • Adds protocol, normalization, capability, and compiler filtering tests.
File Description
tsc/​internal/​contentmapper/​hostimpl.go Advertises, decodes, and validates code selectors.
tsc/​internal/​contentmapper/​host.go Adds an invalid-selector error kind.
tsc/​internal/​contentmapper/​host_test.go Tests selector encoding, normalization, and capability advertisement.
tsc/​internal/​compiler/​program.go Matches diagnostic codes as well as ranges when filtering.
tsc/​internal/​compiler/​contentmapper_test.go Tests suppressing TS2353 while preserving TS2322.
tsc/​internal/​ast/​ast.go Adds the selector to the Go AST directive.
packages/​typescript/​src/​ast/​ast.ts Declares the selector in the TypeScript AST interface.

Review effort: Balanced

Comment thread packages/typescript/src/ast/ast.ts Resolved
Comment thread tsc/internal/contentmapper/hostimpl.go Resolved
Co-authored-by: miyaoka <1443118+miyaoka@users.noreply.github.com>
@ubugeeei

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you foresee any utility in making diagnosticCodes variadic, being able to suppress multiple codes within the same range?

const directives = Array<MappedDiagnosticDirective>(count);
for (let i = 0; i < count; i++) {
if (reader.readArrayHeader() !== 6) throw new Error("Invalid diagnostic directive");
if (reader.readArrayHeader() !== 7) throw new Error("Invalid diagnostic directive");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I intended tuples to be open-ended, not even needing a capability advertisement in order to grow the length. If you move diagnosticCode after unusedCode, and change this to be >= 7, it seems like that would work.

@typescript-automation typescript-automation Bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 19, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Content mapper ignore directives need diagnostic-code selectors

3 participants