Skip to content

Commit 03e2679

Browse files
committed
Bring back the pre cache tweak guarded behind a feature flag
1 parent d1a1f11 commit 03e2679

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Core/Sources/Preferences/Keys.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ public struct UserDefaultPreferenceKeys {
135135
}
136136

137137
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
138+
public var preCacheOnFileOpen: FeatureFlags.PreCacheOnFileOpen { .init() }
138139
}
139140

140141
public enum FeatureFlags {
141142
public struct DisableLazyVStack: UserDefaultPreferenceKey {
142143
public let defaultValue = false
143144
public let key = "FeatureFlag-DisableLazyVStack"
144145
}
146+
147+
public struct PreCacheOnFileOpen: UserDefaultPreferenceKey {
148+
public let defaultValue = true
149+
public let key = "FeatureFlag-PreCacheOnFileOpen"
150+
}
145151
}

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@ public class RealtimeSuggestionController {
134134
}
135135
}
136136
}
137+
138+
Task { // Get cache ready for real-time suggestions.
139+
guard UserDefaults.shared.value(for: \.preCacheOnFileOpen) else { return }
140+
guard
141+
let fileURL = try? await Environment.fetchCurrentFileURL(),
142+
let (_, filespace) = try? await Workspace
143+
.fetchOrCreateWorkspaceIfNeeded(fileURL: fileURL)
144+
else { return }
145+
146+
if filespace.uti == nil {
147+
Logger.service.info("Generate cache for file.")
148+
// avoid the command get called twice
149+
filespace.uti = ""
150+
do {
151+
try await Environment.triggerAction("Real-time Suggestions")
152+
} catch {
153+
if filespace.uti?.isEmpty ?? true {
154+
filespace.uti = nil
155+
}
156+
}
157+
}
158+
}
137159
}
138160

139161
func handleHIDEvent(event: CGEvent) async {

0 commit comments

Comments
 (0)