Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostic format improvements #2143

Merged

Conversation

DougGregor
Copy link
Member

Introduce a few improvements to make the "grouped" diagnostics more similar to the diagnostics provided by the existing Swift compiler, as a step toward enabling these diagnostics by default:

  • Emit the "primary diagnostic" on the first line, matching the style of the existing compiler diagnostics and making it easier for humans tools to find the primary issue.
  • When the "primary diagnostic" is in a generated buffer, such as a macro expansion buffer, also show the outermost source file that triggered the generation of that buffer, so it's easy to find that.
  • Only colorize the severity (error, warning, etc.) and not the whole diagnostic message, to match the Swift compiler's current style.
  • Add remark diagnostic severity, which is used by the Swift compiler and needs to be representable.

Example now:

t.swift:5:3: error: no exact matches in call to global function 'f'
1 │ func f(a: Int) { }
  │      ╰─ note: incorrect labels for candidate (have: '(_:)', expected: '(a:)')
2 │ func f(b: Int) { }
  │      ╰─ note: incorrect labels for candidate (have: '(_:)', expected: '(b:)')
3 │ 
4 │ func g() {
5 │   f(1)
  │   ╰─ error: no exact matches in call to global function 'f'
6 │   f(a: 2.5)
7 │ }

…p front

One of the usability issues with the new grouped diagnostics code is
that the actual error/warning/remark buried within the source code,
with only a header like

    === t.swift:1 ===

to show where the issue occurs. Instead, display the diagnostic
file:line:column and text right up front, the same way as the existing
compiler's style, e.g.,

    t.swift:5:3: error: no exact matches in call to global function 'f'

The is better for humans, because it puts the primary issue right up
front, and also better for tools that scrape logs to find the
diagnostics using this form.
…an expansion

When the primary diagnostic comes from inside some kind of generated
buffer, such as a macro expansion buffer, the file/line/column will
point into a source file that might be temporary. In such cases, also
add a link to the outermost, original source file, e.g.,

    main.swift:2:1: note: expanded code originates here

to help users and tools alike to find that original source file.
Match the existing LLVM style used by the Swift compiler, where the
diagnostic severity (warning, note, error) is colorized and bolded,
but the diagnostic text is bolded but in the default color. Visually,
this is less overwhelming, which is presumably why the compiler has
been doing it.
The Swift compiler (and most LLVM-based tools) have a "remark" diagnostic
severity. Add support for it into DiagnosticSeverity.
@DougGregor
Copy link
Member Author

swiftlang/swift#68289

@swift-ci please test

@DougGregor
Copy link
Member Author

@DougGregor
Copy link
Member Author

@DougGregor
Copy link
Member Author

swiftlang/swift#68289
swiftlang/swift-format#605

@swift-ci please test Windows

@DougGregor
Copy link
Member Author

@DougGregor DougGregor merged commit 9e798fa into swiftlang:main Sep 5, 2023
@DougGregor DougGregor deleted the diagnostic-format-improvements branch September 5, 2023 13:43
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.

2 participants