File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
140141public 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}
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments