diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index e7bf13fc702..7ae09675c49 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -155,7 +155,7 @@ class AppDelegate: NSObject, /// The observer for the app appearance. private var appearanceObserver: NSKeyValueObservation? - private var userDefaultsObserver: NSObjectProtocol? = nil + private var userDefaultsObserver: NSObjectProtocol? private var agentStatusBadgeCancellable: AnyCancellable? /// Signals diff --git a/macos/Sources/Features/GitDiff/DiffParser.swift b/macos/Sources/Features/GitDiff/DiffParser.swift index ad662ec1205..2ea7f5ffaee 100644 --- a/macos/Sources/Features/GitDiff/DiffParser.swift +++ b/macos/Sources/Features/GitDiff/DiffParser.swift @@ -13,7 +13,7 @@ enum DiffParser { var files: [DiffFile] = [] files.reserveCapacity(32) - var current: FileAccumulator? = nil + var current: FileAccumulator? func finishCurrent() { guard var acc = current else { return } @@ -148,7 +148,7 @@ enum DiffParser { var status: DiffFileStatus var hunks: [HunkAccumulator] = [] - var currentHunk: HunkAccumulator? = nil + var currentHunk: HunkAccumulator? var fallbackLines: [String] = [] var additions: Int = 0 @@ -383,11 +383,18 @@ enum DiffParser { return (stripGitDiffPathPrefix(a), stripGitDiffPathPrefix(b)) } - private static func parseHunkHeader(_ line: String) -> (oldStart: Int, oldCount: Int, newStart: Int, newCount: Int) { + struct HunkRange { + let oldStart: Int + let oldCount: Int + let newStart: Int + let newCount: Int + } + + private static func parseHunkHeader(_ line: String) -> HunkRange { let ns = line as NSString let range = NSRange(location: 0, length: ns.length) guard let match = hunkHeaderRegex.firstMatch(in: line, options: [], range: range) else { - return (0, 0, 0, 0) + return HunkRange(oldStart: 0, oldCount: 0, newStart: 0, newCount: 0) } func intGroup(_ idx: Int, default defaultValue: Int) -> Int { guard idx < match.numberOfRanges else { return defaultValue } @@ -396,11 +403,12 @@ enum DiffParser { let s = ns.substring(with: r) return Int(s) ?? defaultValue } - let oldStart = intGroup(1, default: 0) - let oldCount = intGroup(2, default: 1) - let newStart = intGroup(3, default: 0) - let newCount = intGroup(4, default: 1) - return (oldStart, oldCount, newStart, newCount) + return HunkRange( + oldStart: intGroup(1, default: 0), + oldCount: intGroup(2, default: 1), + newStart: intGroup(3, default: 0), + newCount: intGroup(4, default: 1) + ) } private static func stripGitDiffPathPrefix(_ token: String) -> String { diff --git a/macos/Sources/Features/GitDiff/GitDiffMainView.swift b/macos/Sources/Features/GitDiff/GitDiffMainView.swift index 80ffb3bd205..782e7bd13dc 100644 --- a/macos/Sources/Features/GitDiff/GitDiffMainView.swift +++ b/macos/Sources/Features/GitDiff/GitDiffMainView.swift @@ -4,10 +4,10 @@ import SwiftUI struct GitDiffMainView: View { @ObservedObject var state: GitDiffSidebarState - @State private var hoveredLineID: String? = nil - @State private var composer: ComposerLocation? = nil + @State private var hoveredLineID: String? + @State private var composer: ComposerLocation? @State private var composerText: String = "" - @State private var lastVisibleFileID: String? = nil + @State private var lastVisibleFileID: String? var body: some View { content @@ -60,11 +60,11 @@ private struct DiffDocumentView: View { private let lineNumberWidth: CGFloat = 36 private let changeMarkerWidth: CGFloat = 3 @State private var highlightCache = DiffHighlightCache() - @State private var headerOffsetsUpdateTask: Task? = nil + @State private var headerOffsetsUpdateTask: Task? @State private var latestHeaderOffsets: [String: CGFloat] = [:] - @State private var scrollTask: Task? = nil + @State private var scrollTask: Task? @State private var isScrolling: Bool = false - @State private var scrollIdleTask: Task? = nil + @State private var scrollIdleTask: Task? private let initialRenderedFiles: Int = 12 private let renderStep: Int = 8 @@ -416,7 +416,7 @@ private struct DiffLineRow: View { let canHighlight: Bool } - @State private var renderedText: AttributedString? = nil + @State private var renderedText: AttributedString? var body: some View { VStack(alignment: .leading, spacing: 0) { diff --git a/macos/Sources/Features/GitDiff/GitDiffSidebarState.swift b/macos/Sources/Features/GitDiff/GitDiffSidebarState.swift index 6bf656a9f5f..276d9fa4016 100644 --- a/macos/Sources/Features/GitDiff/GitDiffSidebarState.swift +++ b/macos/Sources/Features/GitDiff/GitDiffSidebarState.swift @@ -41,7 +41,7 @@ final class GitDiffSidebarState: ObservableObject { @Published var isVisible: Bool = false @Published var panelWidth: CGFloat = 320 - @Published var repoRoot: String? = nil + @Published var repoRoot: String? @Published var entries: [GitDiffEntry] = [] @Published var source: GitDiffSource = .workingTree { didSet { @@ -53,36 +53,36 @@ final class GitDiffSidebarState: ObservableObject { handleScopeChange() } } - @Published var selectedPath: String? = nil - @Published var currentVisiblePath: String? = nil - @Published var scrollRequest: GitDiffScrollRequest? = nil - @Published var errorMessage: String? = nil + @Published var selectedPath: String? + @Published var currentVisiblePath: String? + @Published var scrollRequest: GitDiffScrollRequest? + @Published var errorMessage: String? @Published var isLoading: Bool = false @Published var diffText: String = "" - @Published var diffError: String? = nil + @Published var diffError: String? @Published var isDiffLoading: Bool = false - @Published var document: DiffDocument? = nil + @Published var document: DiffDocument? @Published var commentsEnabled: Bool = false @Published var reviewDraft: DiffReviewDraft = .empty @Published var collapsedFileIDs: Set = [] @Published var renderedFileCount: Int = 0 - @Published var pullRequest: PRStatus? = nil - @Published var selectedWorktreePath: String? = nil + @Published var pullRequest: PRStatus? + @Published var selectedWorktreePath: String? private var diffRequestID: Int = 0 private var scrollNonce: Int = 0 private let store = GitDiffStore() - private var lastCwd: URL? = nil + private var lastCwd: URL? private let draftStore = DiffReviewDraftStore() - private var refreshTask: Task? = nil - private var pendingRefresh: RefreshRequest? = nil + private var refreshTask: Task? + private var pendingRefresh: RefreshRequest? private var lastRefreshAt: Date = .distantPast - private var pollTask: Task? = nil + private var pollTask: Task? private let watchQueue = DispatchQueue(label: "gitdiff.watch", qos: .utility) private var watchSources: [DispatchSourceFileSystemObject] = [] private var watchFileDescriptors: [Int32] = [] private var watchedPaths: [String] = [] - private var watchedWorktreePath: String? = nil + private var watchedWorktreePath: String? private var ignoreWatchEventsUntil: Date = .distantPast var allCount: Int { diff --git a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift index eac127a2437..4b28744a8a5 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift @@ -38,11 +38,11 @@ class TerminalWindow: NSWindow { private(set) var derivedConfig: DerivedConfig = .init() /// Sets up our tab context menu - private var tabMenuObserver: NSObjectProtocol? = nil - private var titlebarFontTabGroupObservation: NSKeyValueObservation? = nil - private var titlebarFontTabBarObservation: NSKeyValueObservation? = nil - private var lastTitlebarFontState: TitlebarFontState? = nil - private var lastAppliedAppearance: AppearanceState? = nil + private var tabMenuObserver: NSObjectProtocol? + private var titlebarFontTabGroupObservation: NSKeyValueObservation? + private var titlebarFontTabBarObservation: NSKeyValueObservation? + private var lastTitlebarFontState: TitlebarFontState? + private var lastAppliedAppearance: AppearanceState? /// Whether this window supports the update accessory. If this is false, then views within this /// window should determine how to show update notifications. diff --git a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift index 86db73e46e0..eac58e48638 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift @@ -16,7 +16,7 @@ class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSTool private var viewModel = ViewModel() private var worktrunkSidebarWidth: CGFloat = defaultSidebarWidth - private var tabBarLeftConstraint: NSLayoutConstraint? = nil + private var tabBarLeftConstraint: NSLayoutConstraint? private var displayTitle: String = "👻 Ghostree" /// Titlebar tabs can't support the update accessory because of the way we layout /// the native tabs back into the menu bar. @@ -272,7 +272,7 @@ class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSTool func updateWorktrunkSidebarWidth(_ width: CGFloat) { worktrunkSidebarWidth = max(0, width) - let windowButtonsPadding: CGFloat = switch(self.derivedConfig.macosWindowButtons) { + let windowButtonsPadding: CGFloat = switch self.derivedConfig.macosWindowButtons { case .hidden: 0 case .visible: windowControlButtonsWidth } diff --git a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift index aa27424fbe5..990554aceb2 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift @@ -6,7 +6,7 @@ private let defaultSidebarWidth: CGFloat = 280 /// Titlebar tabs for macOS 13 to 15. class TitlebarTabsVenturaTerminalWindow: TerminalWindow { fileprivate var worktrunkSidebarWidth: CGFloat = defaultSidebarWidth - private var windowButtonsBackdropWidthConstraint: NSLayoutConstraint? = nil + private var windowButtonsBackdropWidthConstraint: NSLayoutConstraint? /// Titlebar tabs can't support the update accessory because of the way we layout /// the native tabs back into the menu bar. diff --git a/macos/Sources/Features/Update/UpdatePopoverView.swift b/macos/Sources/Features/Update/UpdatePopoverView.swift index 36703802b7e..827218568f8 100644 --- a/macos/Sources/Features/Update/UpdatePopoverView.swift +++ b/macos/Sources/Features/Update/UpdatePopoverView.swift @@ -220,7 +220,7 @@ private struct UpdateAvailableView: View { } } -fileprivate struct HomebrewUpdateView: View { +private struct HomebrewUpdateView: View { let update: UpdateState.HomebrewUpdate let dismiss: DismissAction diff --git a/macos/Sources/Features/Worktrunk/WorktrunkSidebarView.swift b/macos/Sources/Features/Worktrunk/WorktrunkSidebarView.swift index bd8c61bab73..bd67d3fbf9d 100644 --- a/macos/Sources/Features/Worktrunk/WorktrunkSidebarView.swift +++ b/macos/Sources/Features/Worktrunk/WorktrunkSidebarView.swift @@ -1100,7 +1100,7 @@ private struct CreateWorktreeSheet: View { @State private var base: String = "" @State private var createBranch: Bool = true @State private var isWorking: Bool = false - @State private var errorText: String? = nil + @State private var errorText: String? var body: some View { VStack(alignment: .leading, spacing: 12) { diff --git a/macos/Sources/Features/Worktrunk/WorktrunkStore.swift b/macos/Sources/Features/Worktrunk/WorktrunkStore.swift index 4a01c43a876..f37405c678d 100644 --- a/macos/Sources/Features/Worktrunk/WorktrunkStore.swift +++ b/macos/Sources/Features/Worktrunk/WorktrunkStore.swift @@ -169,8 +169,8 @@ final class SessionIndexManager { } enum WorktreeSortOrder: String, CaseIterable { - case alphabetical = "alphabetical" - case recentActivity = "recentActivity" + case alphabetical + case recentActivity var label: String { switch self { @@ -181,8 +181,8 @@ enum WorktreeSortOrder: String, CaseIterable { } enum WorktrunkSidebarListMode: String { - case nestedByRepo = "nestedByRepo" - case flatWorktrees = "flatWorktrees" + case nestedByRepo + case flatWorktrees } final class WorktrunkStore: ObservableObject { @@ -269,7 +269,7 @@ final class WorktrunkStore: ObservableObject { @Published var isRefreshing: Bool = false @Published var isInstallingWorktrunk: Bool = false @Published var needsWorktrunkInstall: Bool = false - @Published var errorMessage: String? = nil + @Published var errorMessage: String? @Published private(set) var sidebarModelRevision: Int = 0 @Published var worktreeSortOrder: WorktreeSortOrder = .recentActivity { didSet { @@ -295,13 +295,13 @@ final class WorktrunkStore: ObservableObject { private let firstSeenAtKey = "GhostreeWorktrunkWorktreeFirstSeenAtByPath.v1" private let sessionCache = SessionCacheManager() private let sessionIndex = SessionIndexManager() - private var agentEventTailer: AgentEventTailer? = nil + private var agentEventTailer: AgentEventTailer? private var pendingAgentEventsByCwd: [String: AgentLifecycleEvent] = [:] private var agentStatusAckedAtByWorktreePath: [String: Date] = [:] private var firstSeenAtByWorktreePath: [String: Date] = [:] private var lastAppQuitTimestamp: Date? private var sidebarModelRevisionCounter: Int = 0 - private var refreshAllTask: Task? = nil + private var refreshAllTask: Task? private var refreshAllNeedsRerun: Bool = false init() { @@ -631,7 +631,7 @@ final class WorktrunkStore: ObservableObject { await MainActor.run { var removedPaths = Set() var didChangeFirstSeen = false - var lastError: String? = nil + var lastError: String? for repo in repoSnapshot { guard let result = resultsByRepoID[repo.id] else { continue } @@ -1672,7 +1672,7 @@ final class WorktrunkStore: ObservableObject { .appendingPathComponent("session") .appendingPathComponent("message") .appendingPathComponent(info.id) - var messageDirMtime: TimeInterval? = nil + var messageDirMtime: TimeInterval? var messageCount = 0 if let dirAttrs = try? FileManager.default.attributesOfItem(atPath: messageDir.path), let dirMtime = (dirAttrs[.modificationDate] as? Date)?.timeIntervalSince1970 { @@ -1977,7 +1977,7 @@ final class WorktrunkStore: ObservableObject { // MARK: - Session Helpers private func findMatchingWorktree(_ cwd: String) -> String? { - var bestMatch: String? = nil + var bestMatch: String? var bestLength = 0 let normalizedCwd = normalizePathForMatch(cwd)