@@ -38,13 +38,10 @@ struct PseudoCommandHandler {
3838 ) )
3939 }
4040
41- func generateRealtimeSuggestions( ) async {
42- // Can't use handler directly if content is not available.
43- guard let editor = await getEditorContent ( ) else {
44- try ? await Environment . triggerAction ( " Prefetch Suggestions " )
45- return
46- }
47-
41+ func generateRealtimeSuggestions( sourceEditor: AXUIElement ? ) async {
42+ // Can't use handler if content is not available.
43+ guard let editor = await getEditorContent ( sourceEditor: sourceEditor) else { return }
44+
4845 // Otherwise, get it from pseudo handler directly.
4946 let mode = UserDefaults . shared. value ( for: \. suggestionPresentationMode)
5047 switch mode {
@@ -78,7 +75,8 @@ struct PseudoCommandHandler {
7875 guard let focusElement = application. focusedElement,
7976 focusElement. description == " Source Editor "
8077 else { return }
81- guard let ( content, lines, cursorPosition) = await getFileContent ( ) else {
78+ guard let ( content, lines, cursorPosition) = await getFileContent ( sourceEditor: nil )
79+ else {
8280 PresentInWindowSuggestionPresenter ( )
8381 . presentErrorMessage ( " Unable to get file content. " )
8482 return
@@ -147,13 +145,13 @@ struct PseudoCommandHandler {
147145}
148146
149147private extension PseudoCommandHandler {
150- func getFileContent( ) async
148+ func getFileContent( sourceEditor : AXUIElement ? ) async
151149 -> ( content: String , lines: [ String ] , cursorPosition: CursorPosition ) ?
152150 {
153151 guard let xcode = ActiveApplicationMonitor . activeXcode
154152 ?? ActiveApplicationMonitor . latestXcode else { return nil }
155153 let application = AXUIElementCreateApplication ( xcode. processIdentifier)
156- guard let focusElement = application. focusedElement,
154+ guard let focusElement = sourceEditor ?? application. focusedElement,
157155 focusElement. description == " Source Editor "
158156 else { return nil }
159157 guard let selectionRange = focusElement. selectedTextRange else { return nil }
@@ -190,10 +188,10 @@ private extension PseudoCommandHandler {
190188 }
191189
192190 @ServiceActor
193- func getEditorContent( ) async -> EditorContent ? {
191+ func getEditorContent( sourceEditor : AXUIElement ? ) async -> EditorContent ? {
194192 guard
195193 let filespace = await getFilespace ( ) ,
196- let content = await getFileContent ( )
194+ let content = await getFileContent ( sourceEditor : sourceEditor )
197195 else { return nil }
198196 let uti = filespace. uti ?? " "
199197 let tabSize = filespace. tabSize ?? 4
0 commit comments