native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

debug

khoi af8b9697 29d69793

+104 -2
+21 -2
supacode/Features/App/Reducer/AppFeature.swift
··· 47 47 @Dependency(\.terminalClient) private var terminalClient 48 48 49 49 var body: some Reducer<State, Action> { 50 - Reduce { state, action in 50 + let core = Reduce<State, Action> { state, action in 51 51 switch action { 52 52 case .task: 53 53 return .merge( ··· 171 171 return .none 172 172 } 173 173 } 174 - ._printChanges(.actionLabels) 174 + #if DEBUG 175 + core._printChanges(.customDump) 176 + #else 177 + core.printActionLabels() 178 + #endif 175 179 Scope(state: \.repositories, action: \.repositories) { 176 180 RepositoriesFeature() 177 181 } ··· 186 190 } 187 191 } 188 192 } 193 + 194 + private struct ActionLabelReducer<Base: Reducer>: Reducer { 195 + let base: Base 196 + 197 + func reduce(into state: inout Base.State, action: Base.Action) -> Effect<Base.Action> { 198 + print("received action: \(debugCaseOutput(action))") 199 + return base.reduce(into: &state, action: action) 200 + } 201 + } 202 + 203 + private extension Reducer { 204 + func printActionLabels() -> ActionLabelReducer<Self> { 205 + ActionLabelReducer(base: self) 206 + } 207 + }
+83
supacode/Support/DebugCaseOutput.swift
··· 1 + import Foundation 2 + 3 + func debugCaseOutput( 4 + _ value: Any, 5 + abbreviated: Bool = false 6 + ) -> String { 7 + func debugCaseOutputHelp(_ value: Any) -> String { 8 + let mirror = Mirror(reflecting: value) 9 + switch mirror.displayStyle { 10 + case .enum: 11 + guard let child = mirror.children.first else { 12 + let childOutput = "\(value)" 13 + return childOutput == "\(typeName(type(of: value)))" ? "" : ".\(childOutput)" 14 + } 15 + let childOutput = debugCaseOutputHelp(child.value) 16 + return ".\(child.label ?? "")\(childOutput.isEmpty ? "" : "(\(childOutput))")" 17 + case .tuple: 18 + return mirror.children.map { label, value in 19 + let childOutput = debugCaseOutputHelp(value) 20 + let labelValue = label.map { isUnlabeledArgument($0) ? "_:" : "\($0):" } ?? "" 21 + let suffix = childOutput.isEmpty ? "" : " \(childOutput)" 22 + return "\(labelValue)\(suffix)" 23 + } 24 + .joined(separator: ", ") 25 + default: 26 + return "" 27 + } 28 + } 29 + 30 + return (value as? any CustomDebugStringConvertible)?.debugDescription 31 + ?? "\(abbreviated ? "" : typeName(type(of: value)))\(debugCaseOutputHelp(value))" 32 + } 33 + 34 + private func isUnlabeledArgument(_ label: String) -> Bool { 35 + label.firstIndex(where: { $0 != "." && !$0.isNumber }) == nil 36 + } 37 + 38 + private func typeName( 39 + _ type: Any.Type, 40 + qualified: Bool = true, 41 + genericsAbbreviated: Bool = true 42 + ) -> String { 43 + var name = _typeName(type, qualified: qualified) 44 + .replacingOccurrences( 45 + of: #"\(unknown context at \$[[:xdigit:]]+\)\."#, 46 + with: "", 47 + options: .regularExpression 48 + ) 49 + for _ in 1...10 { 50 + let abbreviated = 51 + name 52 + .replacingOccurrences( 53 + of: #"\bSwift.Optional<([^><]+)>"#, 54 + with: "$1?", 55 + options: .regularExpression 56 + ) 57 + .replacingOccurrences( 58 + of: #"\bSwift.Array<([^><]+)>"#, 59 + with: "[$1]", 60 + options: .regularExpression 61 + ) 62 + .replacingOccurrences( 63 + of: #"\bSwift.Dictionary<([^,<]+), ([^><]+)>"#, 64 + with: "[$1: $2]", 65 + options: .regularExpression 66 + ) 67 + if abbreviated == name { break } 68 + name = abbreviated 69 + } 70 + name = name.replacingOccurrences( 71 + of: #"\w+\.([\w.]+)"#, 72 + with: "$1", 73 + options: .regularExpression 74 + ) 75 + if genericsAbbreviated { 76 + name = name.replacingOccurrences( 77 + of: #"<.+>"#, 78 + with: "", 79 + options: .regularExpression 80 + ) 81 + } 82 + return name 83 + }