Added a formatter to pretty print diagnostics#874
Conversation
a1b1415 to
e043a9b
Compare
|
This looks great! |
|
@swift-ci please test |
ahoppen
left a comment
There was a problem hiding this comment.
Thanks a lot, this is great 🤩
I’ve got a couple of comments inline.
ahoppen
left a comment
There was a problem hiding this comment.
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 { | ||
|
|
|
@ahoppen I've added some test cases, and fixed the first bug 😊 |
ahoppen
left a comment
There was a problem hiding this comment.
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.
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 <alex@alexhoppen.de> 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-diagswas 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.