From 83d8826c09df5b96065ff343830a7a9665fb7fa5 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 21:55:38 +0000 Subject: [PATCH 1/2] Fix Swift type-checker timeout in ErrorsTabView Resolves compiler error on line 77 by breaking up complex expressions into distinct sub-expressions: - Extract sorted error types into computed property - Break down chart height calculation into named constants --- Sources/BackgroundTime/ErrorsTabView.swift | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/BackgroundTime/ErrorsTabView.swift b/Sources/BackgroundTime/ErrorsTabView.swift index b9c1a9a..5277cb2 100644 --- a/Sources/BackgroundTime/ErrorsTabView.swift +++ b/Sources/BackgroundTime/ErrorsTabView.swift @@ -69,19 +69,30 @@ public struct ErrorsTabView: View { public struct ErrorSummarySection: View { let errorsByType: [String: Int] - + public init(errorsByType: [String: Int]) { self.errorsByType = errorsByType } - + + private var sortedErrorTypes: [String] { + Array(errorsByType.keys).sorted() + } + + private var chartHeight: CGFloat { + let minHeight: CGFloat = 200.0 + let itemHeight: CGFloat = 30.0 + let calculatedHeight = CGFloat(errorsByType.count) * itemHeight + return max(minHeight, calculatedHeight) + } + public var body: some View { VStack(alignment: .leading, spacing: 12) { Text("Error Types") .font(.headline) .padding(.horizontal) - + Chart { - ForEach(Array(errorsByType.keys).sorted(), id: \.self) { errorType in + ForEach(sortedErrorTypes, id: \.self) { errorType in BarMark( x: .value("Count", errorsByType[errorType] ?? 0), y: .value("Error Type", String(errorType.prefix(30))) @@ -89,7 +100,7 @@ public struct ErrorSummarySection: View { .foregroundStyle(.red) } } - .frame(height: max(200.0, CGFloat(errorsByType.count) * 30.0)) + .frame(height: chartHeight) .padding(.horizontal) } .background(Color(.systemBackground)) From 7452518581c1a1c9701997954fabdeb59a4d6de1 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 22:39:05 +0000 Subject: [PATCH 2/2] Further break down ErrorSummarySection to fix type-checker timeout - Extract helper methods for error count and truncated error type - Split body into smaller computed properties (titleView, errorChart) - Use local let bindings in ForEach to simplify BarMark expressions - Add more intermediate variables in computed properties --- Sources/BackgroundTime/ErrorsTabView.swift | 59 +++++++++++++++------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/Sources/BackgroundTime/ErrorsTabView.swift b/Sources/BackgroundTime/ErrorsTabView.swift index 5277cb2..392f8cf 100644 --- a/Sources/BackgroundTime/ErrorsTabView.swift +++ b/Sources/BackgroundTime/ErrorsTabView.swift @@ -75,35 +75,58 @@ public struct ErrorSummarySection: View { } private var sortedErrorTypes: [String] { - Array(errorsByType.keys).sorted() + let keys = Array(errorsByType.keys) + return keys.sorted() } private var chartHeight: CGFloat { let minHeight: CGFloat = 200.0 let itemHeight: CGFloat = 30.0 - let calculatedHeight = CGFloat(errorsByType.count) * itemHeight + let count = errorsByType.count + let calculatedHeight = CGFloat(count) * itemHeight return max(minHeight, calculatedHeight) } + private func errorCount(for errorType: String) -> Int { + return errorsByType[errorType] ?? 0 + } + + private func truncatedErrorType(_ errorType: String) -> String { + let prefix = errorType.prefix(30) + return String(prefix) + } + public var body: some View { - VStack(alignment: .leading, spacing: 12) { - Text("Error Types") - .font(.headline) - .padding(.horizontal) + let content = VStack(alignment: .leading, spacing: 12) { + titleView + errorChart + } - Chart { - ForEach(sortedErrorTypes, id: \.self) { errorType in - BarMark( - x: .value("Count", errorsByType[errorType] ?? 0), - y: .value("Error Type", String(errorType.prefix(30))) - ) - .foregroundStyle(.red) - } - } - .frame(height: chartHeight) + return content + .background(Color(.systemBackground)) + .cornerRadius(12) + } + + private var titleView: some View { + Text("Error Types") + .font(.headline) .padding(.horizontal) + } + + private var errorChart: some View { + Chart { + ForEach(sortedErrorTypes, id: \.self) { errorType in + let count = errorCount(for: errorType) + let label = truncatedErrorType(errorType) + + BarMark( + x: .value("Count", count), + y: .value("Error Type", label) + ) + .foregroundStyle(.red) + } } - .background(Color(.systemBackground)) - .cornerRadius(12) + .frame(height: chartHeight) + .padding(.horizontal) } } \ No newline at end of file