Skip to content

[SwiftDiagnostics] Render attached notes in GroupedDiagnostics#3364

Open
ihormalovanyi wants to merge 1 commit into
swiftlang:mainfrom
ihormalovanyi:render-grouped-diagnostics-notes
Open

[SwiftDiagnostics] Render attached notes in GroupedDiagnostics#3364
ihormalovanyi wants to merge 1 commit into
swiftlang:mainfrom
ihormalovanyi:render-grouped-diagnostics-notes

Conversation

@ihormalovanyi

Copy link
Copy Markdown

Summary

GroupedDiagnostics only handed the top-level diagnostics to DiagnosticsFormatter, so any notes attached to a Diagnostic — which have their own location and message — were never rendered. This fixes #2166 by expanding each diagnostic's notes into .note-severity diagnostics before formatting, so they are laid out at their locations the same way top-level diagnostics are.

Implementation

  • Added a small NoteAsDiagnosticMessage adapter that presents a NoteMessage as a .note-severity DiagnosticMessage, plus a Note.asDiagnostic helper. Both are file-private; there is no public API change.
  • annotateSource now flattens [diagnostic] + diagnostic.notes before passing the list to the formatter. Primary-diagnostic selection is unchanged, so the header still reports the error/warning rather than a note.

Testing

  • New testAttachedNotesAreRendered, covering a diagnostic with one attached note.
  • testGroupingForMacroExpansion's expected output is updated: the parser's real "to match this opening '('" note attached to the "expected ')'" error is now rendered (it was previously dropped), which doubles as evidence of the fix.

Out of scope (noted in #2166)

  • Fix-Its are still not rendered by GroupedDiagnostics.
  • Notes that point into a different source buffer than their diagnostic are flattened as-is; refining cross-buffer note placement could be done separately.

GroupedDiagnostics passed only the top-level diagnostics to the formatter, so notes attached to a diagnostic (which carry their own location and message) were silently dropped. Expand each diagnostic's notes into note-severity diagnostics so the formatter renders them at their locations alongside the diagnostic.

Fixes swiftlang#2166.
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.

GroupedDiagnostics does not handle notes on diagnostics

1 participant