Skip to content
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

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

Merged
merged 2 commits into from Jan 22, 2023

Conversation

DougGregor
Copy link
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
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

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

ahoppen commented Jan 23, 2023

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

@@ -32,7 +32,7 @@ class DiagnosticOptions {
VerifyAndApplyFixes
} VerifyMode = NoVerify;

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

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.

None yet

3 participants