File tree Expand file tree Collapse file tree 1 file changed +17
-9
lines changed
Core/Sources/Service/SuggestionCommandHandler Expand file tree Collapse file tree 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -39,20 +39,28 @@ struct PseudoCommandHandler {
3939 }
4040
4141 func generateRealtimeSuggestions( ) async {
42+ // Can't use handler directly if content is not available.
4243 guard let editor = await getEditorContent ( ) else {
4344 try ? await Environment . triggerAction ( " Prefetch Suggestions " )
4445 return
4546 }
47+
48+ // If no cache is available, and completion panel is not displayed, try to get it with command.
49+ if editor. uti. isEmpty, await Environment . frontmostXcodeWindowIsEditor ( ) {
50+ try ? await Environment . triggerAction ( " Prefetch Suggestions " )
51+ return
52+ }
53+
54+ // Otherwise, get it from pseudo handler directly.
4655 let mode = UserDefaults . shared. value ( for: \. suggestionPresentationMode)
47- let handler : SuggestionCommandHandler = {
48- switch mode {
49- case . comment:
50- return CommentBaseCommandHandler ( )
51- case . floatingWidget:
52- return WindowBaseCommandHandler ( )
53- }
54- } ( )
55- _ = try ? await handler. generateRealtimeSuggestions ( editor: editor)
56+ switch mode {
57+ case . comment:
58+ let handler = CommentBaseCommandHandler ( )
59+ _ = try ? await handler. generateRealtimeSuggestions ( editor: editor)
60+ case . floatingWidget:
61+ let handler = WindowBaseCommandHandler ( )
62+ _ = try ? await handler. generateRealtimeSuggestions ( editor: editor)
63+ }
5664 }
5765
5866 func rejectSuggestions( ) async {
You can’t perform that action at this time.
0 commit comments