Skip to content

Commit 0135850

Browse files
committed
Make command Real-time Suggestion return immediately for window mode
1 parent d251406 commit 0135850

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

EditorExtension/RealtimeSuggestionCommand.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@ class RealtimeSuggestionsCommand: NSObject, XCSourceEditorCommand, CommandType {
1010
with invocation: XCSourceEditorCommandInvocation,
1111
completionHandler: @escaping (Error?) -> Void
1212
) {
13-
Task {
14-
do {
15-
let service = try getService()
16-
if let content = try await service.getRealtimeSuggestedCode(
17-
editorContent: .init(invocation)
18-
) {
19-
invocation.accept(content)
13+
switch UserDefaults.shared.value(for: \.suggestionPresentationMode) {
14+
case .comment:
15+
Task {
16+
do {
17+
let service = try getService()
18+
if let content = try await service.getRealtimeSuggestedCode(
19+
editorContent: .init(invocation)
20+
) {
21+
invocation.accept(content)
22+
}
23+
completionHandler(nil)
24+
} catch is CancellationError {
25+
completionHandler(nil)
26+
} catch {
27+
completionHandler(error)
2028
}
21-
completionHandler(nil)
22-
} catch is CancellationError {
23-
completionHandler(nil)
24-
} catch {
25-
completionHandler(error)
29+
}
30+
case .floatingWidget:
31+
completionHandler(nil)
32+
Task {
33+
let service = try getService()
34+
_ = try await service.getRealtimeSuggestedCode(editorContent: .init(invocation))
2635
}
2736
}
2837
}

0 commit comments

Comments
 (0)