[SwiftSyntax] Publicize DiagnosticEngine.addConsumer and add hasErrors property (#14996)

* [SwiftSyntax] Publicize DiagnosticEngine.addConsumer and add hasErrors property

* [Syntax] Make DiagnosticEngine.hasErrors public
This commit is contained in:
Harlan
2018-03-06 00:40:24 -05:00
committed by GitHub
parent 11e3d16c93
commit d3f6b8743d
2 changed files with 10 additions and 3 deletions

View File

@@ -27,7 +27,7 @@ public class DiagnosticEngine {
public private(set) var diagnostics = [Diagnostic]()
/// Adds the provided consumer to the consumers list.
func addConsumer(_ consumer: DiagnosticConsumer) {
public func addConsumer(_ consumer: DiagnosticConsumer) {
consumers.append(consumer)
// Start the consumer with all previous diagnostics.
@@ -44,7 +44,7 @@ public class DiagnosticEngine {
public func diagnose(_ message: Diagnostic.Message,
location: SourceLocation? = nil,
actions: ((inout Diagnostic.Builder) -> Void)? = nil) {
let diagnostic = Diagnostic(message: message, location: location,
let diagnostic = Diagnostic(message: message, location: location,
actions: actions)
diagnostics.append(diagnostic)
for consumer in consumers {
@@ -52,6 +52,11 @@ public class DiagnosticEngine {
}
}
/// If any of the diagnostics in this engine have the `error` severity.
public var hasErrors: Bool {
return diagnostics.contains(where: { $0.message.severity == .error })
}
/// Tells each consumer to finalize their diagnostic output.
deinit {
for consumer in consumers {