|
| 1 | +// MARK: - ProgressReporting |
| 2 | + |
| 3 | +public struct ProgressReporting { |
| 4 | + let print: (String) -> Void |
| 5 | + |
| 6 | + public init(verbose: Bool) { |
| 7 | + self.init(print: verbose ? { Swift.print($0) } : { _ in }) |
| 8 | + } |
| 9 | + |
| 10 | + private init(print: @escaping (String) -> Void) { |
| 11 | + self.print = print |
| 12 | + } |
| 13 | + |
| 14 | + public static var silent: ProgressReporting { |
| 15 | + return ProgressReporting(print: { _ in }) |
| 16 | + } |
| 17 | + |
| 18 | + public func print(_ message: String) { |
| 19 | + self.print(message) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +// MARK: - DiagnosticError |
| 24 | + |
| 25 | +import SwiftSyntax |
| 26 | + |
| 27 | +struct DiagnosticError: Error { |
| 28 | + let node: Syntax |
| 29 | + let message: String |
| 30 | + let hint: String? |
| 31 | + |
| 32 | + init(node: some SyntaxProtocol, message: String, hint: String? = nil) { |
| 33 | + self.node = Syntax(node) |
| 34 | + self.message = message |
| 35 | + self.hint = hint |
| 36 | + } |
| 37 | + |
| 38 | + func formattedDescription(fileName: String) -> String { |
| 39 | + let locationConverter = SourceLocationConverter(fileName: fileName, tree: node.root) |
| 40 | + let location = locationConverter.location(for: node.position) |
| 41 | + var description = "\(fileName):\(location.line):\(location.column): error: \(message)" |
| 42 | + if let hint { |
| 43 | + description += "\nHint: \(hint)" |
| 44 | + } |
| 45 | + return description |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +// MARK: - BridgeJSCoreError |
| 50 | + |
| 51 | +public struct BridgeJSCoreError: Swift.Error, CustomStringConvertible { |
| 52 | + public let description: String |
| 53 | + |
| 54 | + public init(_ message: String) { |
| 55 | + self.description = message |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// MARK: - BridgeJSConfig |
| 60 | + |
1 | 61 | import struct Foundation.URL |
2 | 62 | import struct Foundation.Data |
3 | 63 | import class Foundation.FileManager |
|
0 commit comments