Skip to content

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

Merged
merged 1 commit into from
Oct 5, 2022

Conversation

flashspys
Copy link
Contributor

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:
image

With this PR the output will look like the following:
image

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:

193467557-e64cbe07-9bf6-482e-8ccb-60f11067fe09 copy

In future pull request I want to add more functionality to this, including colored output and display of hints, fixits and notes.

@flashspys flashspys requested a review from ahoppen as a code owner October 2, 2022 17:32
@flashspys flashspys force-pushed the diagnostics-formatter branch from a1b1415 to e043a9b Compare October 3, 2022 20:37
@DougGregor
Copy link
Member

This looks great!

@DougGregor
Copy link
Member

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a 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.

@flashspys flashspys requested a review from ahoppen October 4, 2022 15:43
Copy link
Member

@ahoppen ahoppen left a 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 {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous newline

@flashspys
Copy link
Contributor Author

@ahoppen I've added some test cases, and fixed the first bug 😊

Copy link
Member

@ahoppen ahoppen left a 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
Copy link
Member

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_
@flashspys flashspys force-pushed the diagnostics-formatter branch from e7c04b7 to 34c67ee Compare October 5, 2022 06:56
@ahoppen
Copy link
Member

ahoppen commented Oct 5, 2022

@swift-ci Please test

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.

3 participants