Skip to content

Commit 48099f9

Browse files
committed
Update pseudo handler to use command to get real-time suggestion when needed and possible
1 parent 53a1c64 commit 48099f9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)