File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,27 @@ public class RealtimeSuggestionController {
134134 }
135135 }
136136 }
137+
138+ Task { // Get cache ready for real-time suggestions.
139+ guard
140+ let fileURL = try ? await Environment . fetchCurrentFileURL ( ) ,
141+ let ( _, filespace) = try ? await Workspace
142+ . fetchOrCreateWorkspaceIfNeeded ( fileURL: fileURL)
143+ else { return }
144+
145+ if filespace. uti == nil {
146+ Logger . service. info ( " Generate cache for file. " )
147+ // avoid the command get called twice
148+ filespace. uti = " "
149+ do {
150+ try await Environment . triggerAction ( " Real-time Suggestions " )
151+ } catch {
152+ if filespace. uti? . isEmpty ?? true {
153+ filespace. uti = nil
154+ }
155+ }
156+ }
157+ }
137158 }
138159
139160 func handleHIDEvent( event: CGEvent ) async {
Original file line number Diff line number Diff line change @@ -168,7 +168,20 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
168168 }
169169
170170 func presentRealtimeSuggestions( editor: EditorContent ) async throws -> UpdatedContent ? {
171- // not needed.
171+ Task {
172+ try ? await prepareCache ( editor: editor)
173+ }
174+ return nil
175+ }
176+
177+ func prepareCache( editor: EditorContent ) async throws -> UpdatedContent ? {
178+ let fileURL = try await Environment . fetchCurrentFileURL ( )
179+ let ( _, filespace) = try await Workspace
180+ . fetchOrCreateWorkspaceIfNeeded ( fileURL: fileURL)
181+ filespace. uti = editor. uti
182+ filespace. tabSize = editor. tabSize
183+ filespace. indentSize = editor. indentSize
184+ filespace. usesTabsForIndentation = editor. usesTabsForIndentation
172185 return nil
173186 }
174187
You can’t perform that action at this time.
0 commit comments