Skip to content

Added a formatter to pretty print diagnostics#874

Merged
ahoppen merged 1 commit intoswiftlang:mainfrom
flashspys:diagnostics-formatter
Oct 5, 2022
Merged

Added a formatter to pretty print diagnostics#874
ahoppen merged 1 commit intoswiftlang:mainfrom
flashspys:diagnostics-formatter

Conversation

@flashspys
Copy link
Copy Markdown
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
Copy Markdown
Member

This looks great!

@DougGregor
Copy link
Copy Markdown
Member

@swift-ci please test

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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
Copy Markdown
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 <alex@alexhoppen.de>

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
Copy Markdown
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