Skip to content

Fix formatting of locationless related diagnostics - #65592

Open
Ishaan Gautam (TheNightCoder21) wants to merge 1 commit into
microsoft:mainfrom
TheNightCoder21:fix/diagnostic-related-information
Open

Ishaan Gautam (TheNightCoder21) wants to merge 1 commit into
microsoft:mainfrom
TheNightCoder21:fix/diagnostic-related-information

Conversation

@TheNightCoder21

Copy link
Copy Markdown

Summary

Fixes #65087.

formatDiagnosticsWithColorAndContext currently formats related diagnostic messages only when the related diagnostic has both a file name and a start position. Consequently, related messages without source locations, including their nested message chains, are silently omitted.

This change:

  • Formats related diagnostic message text regardless of whether source-location information is available.
  • Keeps location headings and source-code context conditional on the availability of the required location data.
  • Preserves indentation for nested message chains when the related diagnostic has no location.
  • Adds regression coverage for located and locationless related information, nested message chains, partial location data, LF/CRLF newlines, and diagnostics without related information.

Testing

  • npx hereby validate --all
  • npx hereby tidy
  • git diff --check

All listed checks passed.

The regression test covers both the existing located-diagnostic behavior and the previously missing locationless-diagnostic behavior.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 20:35
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 19, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 19, 2026

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.

🟢 Approval recommended

No active review issues were identified in the change to preserve related diagnostic messages without source locations.

No open issues 🎉

What changed in this PR

Fixes #65087 in the native TypeScript API by preserving related diagnostic messages even when they lack source locations.

Changes:

  • Emits related message text independently of location headings and source context.
  • Preserves indentation for nested related message chains.
  • Adds regression coverage for located, locationless, and partial-location diagnostics, LF/CRLF newlines, and absent related information.
File Description
packages/​typescript/​test/​diagnosticFormatter.test.ts Adds regression coverage for related diagnostic formatting and edge cases.
packages/​typescript/​src/​api/​diagnosticFormatter.ts Separates related message output from location checks and carries base indentation through nested messages.

Review effort: Balanced

@TheNightCoder21

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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 Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Native API: formatDiagnosticsWithColorAndContext drops related information without a file location

2 participants