[SwiftDiagnostics] Render attached notes in GroupedDiagnostics#3364
Open
ihormalovanyi wants to merge 1 commit into
Open
[SwiftDiagnostics] Render attached notes in GroupedDiagnostics#3364ihormalovanyi wants to merge 1 commit into
ihormalovanyi wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GroupedDiagnosticsonly handed the top-level diagnostics toDiagnosticsFormatter, so any notes attached to aDiagnostic— which have their ownlocationandmessage— were never rendered. This fixes #2166 by expanding each diagnostic'snotesinto.note-severity diagnostics before formatting, so they are laid out at their locations the same way top-level diagnostics are.Implementation
NoteAsDiagnosticMessageadapter that presents aNoteMessageas a.note-severityDiagnosticMessage, plus aNote.asDiagnostichelper. Both are file-private; there is no public API change.annotateSourcenow flattens[diagnostic] + diagnostic.notesbefore passing the list to the formatter. Primary-diagnostic selection is unchanged, so the header still reports the error/warning rather than a note.Testing
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)
GroupedDiagnostics.