-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Capture code snippet from diagnostic compiler output #9362
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
base: main
Are you sure you want to change the base?
Changes from 16 commits
235dd3e
f9dfdf3
b1ff231
ac6b81b
1ae0f38
b81bfca
f3aaabf
c48e606
f14600c
359331a
56f0a45
dd1505a
08306e2
424492f
4074c59
05ee043
7a00f35
e88ab96
5f0911d
8f713a0
fd21a42
7a91843
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,10 @@ public class ObservabilitySystem { | |
| func handleDiagnostic(scope: ObservabilityScope, diagnostic: Diagnostic) { | ||
| self.underlying(scope, diagnostic) | ||
| } | ||
|
|
||
| func printToOutput(message: String) { | ||
| self.diagnosticsHandler.printToOutput(message: message) | ||
| } | ||
| } | ||
|
|
||
| public static var NOOP: ObservabilityScope { | ||
|
|
@@ -128,6 +132,10 @@ public final class ObservabilityScope: DiagnosticsEmitterProtocol, Sendable, Cus | |
| return parent?.errorsReportedInAnyScope ?? false | ||
| } | ||
|
|
||
| public func print(message: String) { | ||
| self.diagnosticsHandler.printToOutput(message: message) | ||
| } | ||
|
|
||
| // DiagnosticsEmitterProtocol | ||
| public func emit(_ diagnostic: Diagnostic) { | ||
| var diagnostic = diagnostic | ||
|
|
@@ -150,6 +158,10 @@ public final class ObservabilityScope: DiagnosticsEmitterProtocol, Sendable, Cus | |
| self.underlying.handleDiagnostic(scope: scope, diagnostic: diagnostic) | ||
| } | ||
|
|
||
| public func printToOutput(message: String) { | ||
| self.underlying.printToOutput(message: message) | ||
| } | ||
|
|
||
| var errorsReported: Bool { | ||
| self._errorsReported.get() ?? false | ||
| } | ||
|
|
@@ -160,6 +172,8 @@ public final class ObservabilityScope: DiagnosticsEmitterProtocol, Sendable, Cus | |
|
|
||
| public protocol DiagnosticsHandler: Sendable { | ||
| func handleDiagnostic(scope: ObservabilityScope, diagnostic: Diagnostic) | ||
|
|
||
| func printToOutput(message: String) | ||
|
||
| } | ||
|
|
||
| /// Helper protocol to share default behavior. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this
func print(_ output: String, verbose: Bool)instead? Since we already have a viable implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's the
DiagnosticHandlersresponsibility to print the diagnostic here. We should instead have a "LoggingHandler" which would know where to emit the "message", whether it's to stdout, stderr, to a file, or some other place.