-
Notifications
You must be signed in to change notification settings - Fork 441
Added a formatter to pretty print diagnostics #874
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
Conversation
a1b1415
to
e043a9b
Compare
This looks great! |
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, this is great 🤩
I’ve got a couple of comments inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good. I’ve got a couple new comments inline. Also, now that DiagnosticsFormatter
returns a string instead of printing, you could add a couple of test cases for it.
|
||
/// Print given diagnostics for a given syntax tree on the command line | ||
public static func annotatedSource(tree: SourceFileSyntax, diags: [Diagnostic]) -> String { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous newline
@ahoppen I've added some test cases, and fixed the first bug 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me. I’ve got one more minor comment for the test cases. Afterwards, could you squash your commits and we can 🚢it.
// | ||
//===----------------------------------------------------------------------===// | ||
import XCTest | ||
@_spi(Testing) import SwiftDiagnostics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think this needs to be @_spi(Testing)
because we don’t have any types or functions in SwiftDiagnostics annotated with @_spi(Testing)
Update DiagnosticsFormatter.swift Use correct fileheader typo simplify if statement Applied QA Remove old diagnostics printing Applied QA Remove superfluous line Update Sources/SwiftDiagnostics/DiagnosticsFormatter.swift Co-authored-by: Alex Hoppen <[email protected]> Add some test cases Remove unnecessary @spi_
e7c04b7
to
34c67ee
Compare
@swift-ci Please test |
Hello swift-syntax team 👋,
in my first PR for this project I want to add a diagnostics formatter to this project. The output from

swift-parser-test print-diags
was not very pretty:With this PR the output will look like the following:

Currently, the formatter will print any number of error messages next to the original source lines. It is already even capable of printing only affected lines in bigger files, including some context:
In future pull request I want to add more functionality to this, including colored output and display of hints, fixits and notes.