Skip to content

[Diagnostics] Add a swift-syntax diagnostic style#63153

Merged
DougGregor merged 2 commits intoswiftlang:mainfrom
DougGregor:swift-syntax-diagnostic-style
Jan 22, 2023
Merged

[Diagnostics] Add a swift-syntax diagnostic style#63153
DougGregor merged 2 commits intoswiftlang:mainfrom
DougGregor:swift-syntax-diagnostic-style

Conversation

@DougGregor
Copy link
Copy Markdown
Member

The SwiftDiagnostics module within swift-syntax has a diagnostic pretty-printer that does a nice rendering of the source code with diagnostics placed inside gaps between the code lines. Introduce another -diagnostic-style argument, swift-syntax, to bridge from the pretty-printed C++ diagnostics over to the swift-syntax diagnostics engine.

The diagnostics emitted here are pretty nice, but can certainly be improved with some work on the swift-syntax formatter itself:

=== macro_expand.swift ===
 89    _ = #addBlocker(a * b * c)
 90  #if TEST_DIAGNOSTICS
 91    _ = #addBlocker(a + b * c)
                         ├─ blocked an add; did you mean to subtract? (from macro 'addBlocker')
                         ╰─ use '-'
 92    
 93    _ = #addBlocker(oa + oa)
                          ├─ blocked an add; did you mean to subtract? (from macro 'addBlocker')
                          ╰─ use '-'
 94 
 95 

=== macro:addBlocker:macro_expand.swift:93:7-93:27 ===
1  oa - oa
      ╰─ binary operator '-' cannot be applied to two 'OnlyAdds' operands

The SwiftDiagnostics module within swift-syntax has a diagnostic
pretty-printer that does a nice rendering of the source code with
diagnostics placed inside gaps between the code lines.
Introduce another `-diagnostic-style` argument, `swift-syntax`,
to bridge from the pretty-printed C++ diagnostics over to the
swift-syntax diagnostics engine.
@DougGregor
Copy link
Copy Markdown
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Copy Markdown
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit fa845d8 into swiftlang:main Jan 22, 2023
@DougGregor DougGregor deleted the swift-syntax-diagnostic-style branch January 22, 2023 21:44
@ahoppen
Copy link
Copy Markdown
Member

ahoppen commented Jan 23, 2023

Thanks to @flashspys for implementing the nice diagnostics formatter on the SwiftSyntax side.

} VerifyMode = NoVerify;

enum FormattingStyle { LLVM, Swift };
enum FormattingStyle { LLVM, Swift, SwiftSyntax };
Copy link
Copy Markdown
Collaborator

@AnthonyLatsis AnthonyLatsis Jan 28, 2023

Choose a reason for hiding this comment

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

Should we update Options.td to mention this new option?

Edit: Probably a bad idea if we want it to supersede the "swift" formatter eventually.

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