Skip to content

Commit 61e7e37

Browse files
committed
also bridge data
1 parent c34839a commit 61e7e37

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

Sources/Basics/Observability.swift

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,22 @@ extension TSCDiagnostic {
510510
location = UnknownLocation.location
511511
}
512512

513+
let data: DiagnosticData
514+
if let legacyData = diagnostic.metadata?.legacyDiagnosticData {
515+
data = legacyData.underlying
516+
} else {
517+
data = StringDiagnostic(diagnostic.message)
518+
}
519+
513520
switch diagnostic.severity {
514521
case .error:
515-
self = .init(message: .error(diagnostic.message), location: location)
522+
self = .init(message: .error(data), location: location)
516523
case .warning:
517-
self = .init(message: .warning(diagnostic.message), location: location)
524+
self = .init(message: .warning(data), location: location)
518525
case .info:
519-
self = .init(message: .note(diagnostic.message), location: location)
526+
self = .init(message: .note(data), location: location)
520527
case .debug:
521-
self = .init(message: .note(diagnostic.message), location: location)
528+
self = .init(message: .note(data), location: location)
522529
}
523530
}
524531
}
@@ -534,11 +541,11 @@ extension ObservabilityMetadata {
534541
}
535542
}
536543

537-
enum LegacyLocationKey: Key {
544+
fileprivate enum LegacyLocationKey: Key {
538545
typealias Value = DiagnosticLocationWrapper
539546
}
540547

541-
public struct DiagnosticLocationWrapper: DiagnosticLocation {
548+
public struct DiagnosticLocationWrapper: CustomStringConvertible {
542549
let underlying: DiagnosticLocation
543550

544551
public init (_ underlying: DiagnosticLocation) {
@@ -550,3 +557,31 @@ extension ObservabilityMetadata {
550557
}
551558
}
552559
}
560+
561+
//@available(*, deprecated, message: "temporary for transition DiagnosticsEngine -> DiagnosticsEmitter")
562+
extension ObservabilityMetadata {
563+
fileprivate var legacyDiagnosticData: DiagnosticDataWrapper? {
564+
get {
565+
self[LegacyDataKey.self]
566+
}
567+
set {
568+
self[LegacyDataKey.self] = newValue
569+
}
570+
}
571+
572+
fileprivate enum LegacyDataKey: Key {
573+
typealias Value = DiagnosticDataWrapper
574+
}
575+
576+
fileprivate struct DiagnosticDataWrapper: CustomStringConvertible {
577+
let underlying: DiagnosticData
578+
579+
public init (_ underlying: DiagnosticData) {
580+
self.underlying = underlying
581+
}
582+
583+
public var description: String {
584+
self.underlying.description
585+
}
586+
}
587+
}

0 commit comments

Comments
 (0)