Skip to content

Commit 0557b54

Browse files
committed
Say goodbye to comment mode
1 parent 35d3895 commit 0557b54

File tree

10 files changed

+27
-160
lines changed

10 files changed

+27
-160
lines changed

Core/Sources/Service/GUI/RealtimeSuggestionIndicatorController.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import QuartzCore
99
import SwiftUI
1010
import UserDefaultsObserver
1111

12-
/// Present a tiny dot next to mouse cursor if real-time suggestion is enabled.
12+
/// Deprecated: This class is no longer in use.
13+
@available(*, deprecated, message: "This class is no longer in use.")
1314
@MainActor
1415
final class RealtimeSuggestionIndicatorController {
1516
class IndicatorContentViewModel: ObservableObject {
@@ -226,10 +227,8 @@ final class RealtimeSuggestionIndicatorController {
226227
private func updateIndicatorVisibility() async {
227228
let isVisible = await {
228229
let isOn = UserDefaults.shared.value(for: \.realtimeSuggestionToggle)
229-
let isCommentMode = UserDefaults.shared
230-
.value(for: \.suggestionPresentationMode) == .comment
231230
let isXcodeActive = await Environment.isXcodeActive()
232-
return isOn && isXcodeActive && isCommentMode
231+
return isOn && isXcodeActive
233232
}()
234233

235234
guard window.isVisible != isVisible else { return }

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public class RealtimeSuggestionController {
2828
private var focusedUIElement: AXUIElement?
2929
private var sourceEditor: SourceEditor?
3030

31-
var isCommentMode: Bool {
32-
UserDefaults.shared.value(for: \.suggestionPresentationMode) == .comment
33-
}
34-
3531
private nonisolated init() {
3632
Task { [weak self] in
3733

@@ -179,16 +175,6 @@ public class RealtimeSuggestionController {
179175
if keycode == escape {
180176
if event.type == .keyDown {
181177
await cancelInFlightTasks()
182-
} else {
183-
Task {
184-
#warning(
185-
"TODO: Any method to avoid using AppleScript to check that completion panel is presented?"
186-
)
187-
if isCommentMode, await Environment.frontmostXcodeWindowIsEditor() {
188-
if Task.isCancelled { return }
189-
self.triggerPrefetchDebounced(force: true)
190-
}
191-
}
192178
}
193179
}
194180
}
@@ -214,11 +200,6 @@ public class RealtimeSuggestionController {
214200

215201
Logger.service.info("Prefetch suggestions.")
216202

217-
if !force, isCommentMode, await !Environment.frontmostXcodeWindowIsEditor() {
218-
Logger.service.info("Completion panel is open, blocked.")
219-
return
220-
}
221-
222203
// So the editor won't be blocked (after information are cached)!
223204
await PseudoCommandHandler().generateRealtimeSuggestions(sourceEditor: sourceEditor)
224205
}

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,8 @@ struct PseudoCommandHandler {
5656
}
5757

5858
// Otherwise, get it from pseudo handler directly.
59-
let mode = UserDefaults.shared.value(for: \.suggestionPresentationMode)
60-
switch mode {
61-
case .comment:
62-
let handler = CommentBaseCommandHandler()
63-
_ = try? await handler.generateRealtimeSuggestions(editor: editor)
64-
case .floatingWidget:
65-
let handler = WindowBaseCommandHandler()
66-
_ = try? await handler.generateRealtimeSuggestions(editor: editor)
67-
}
59+
let handler = WindowBaseCommandHandler()
60+
_ = try? await handler.generateRealtimeSuggestions(editor: editor)
6861
}
6962

7063
func invalidateRealtimeSuggestionsIfNeeded(sourceEditor: SourceEditor) async {

Core/Sources/Service/XPCService.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
4747
do {
4848
let editor = try JSONDecoder().decode(EditorContent.self, from: editorContent)
4949
let mode = UserDefaults.shared.value(for: \.suggestionPresentationMode)
50-
let handler: SuggestionCommandHandler = {
51-
switch mode {
52-
case .comment:
53-
return CommentBaseCommandHandler()
54-
case .floatingWidget:
55-
return WindowBaseCommandHandler()
56-
}
57-
}()
50+
let handler: SuggestionCommandHandler = WindowBaseCommandHandler()
5851
try Task.checkCancellation()
5952
guard let updatedContent = try await getUpdatedContent(handler, editor) else {
6053
reply(nil, nil)

EditorExtension/GetSuggestionsCommand.swift

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,10 @@ class GetSuggestionsCommand: NSObject, XCSourceEditorCommand, CommandType {
1010
with invocation: XCSourceEditorCommandInvocation,
1111
completionHandler: @escaping (Error?) -> Void
1212
) {
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.getSuggestedCode(
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)
28-
}
29-
}
30-
case .floatingWidget:
31-
completionHandler(nil)
32-
Task {
33-
let service = try getService()
34-
_ = try await service.getSuggestedCode(editorContent: .init(invocation))
35-
}
13+
completionHandler(nil)
14+
Task {
15+
let service = try getService()
16+
_ = try await service.getSuggestedCode(editorContent: .init(invocation))
3617
}
3718
}
3819
}

EditorExtension/NextSuggestionCommand.swift

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

EditorExtension/PreviousSuggestionCommand.swift

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,10 @@ class PreviousSuggestionCommand: NSObject, XCSourceEditorCommand, CommandType {
1010
with invocation: XCSourceEditorCommandInvocation,
1111
completionHandler: @escaping (Error?) -> Void
1212
) {
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.getPreviousSuggestedCode(
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)
28-
}
29-
}
30-
case .floatingWidget:
31-
completionHandler(nil)
32-
Task {
33-
let service = try getService()
34-
_ = try await service.getPreviousSuggestedCode(editorContent: .init(invocation))
35-
}
13+
completionHandler(nil)
14+
Task {
15+
let service = try getService()
16+
_ = try await service.getPreviousSuggestedCode(editorContent: .init(invocation))
3617
}
3718
}
3819
}

EditorExtension/RealtimeSuggestionCommand.swift

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,10 @@ class RealtimeSuggestionsCommand: NSObject, XCSourceEditorCommand, CommandType {
1010
with invocation: XCSourceEditorCommandInvocation,
1111
completionHandler: @escaping (Error?) -> Void
1212
) {
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)
28-
}
29-
}
30-
case .floatingWidget:
31-
completionHandler(nil)
32-
Task {
33-
let service = try getService()
34-
_ = try await service.getRealtimeSuggestedCode(editorContent: .init(invocation))
35-
}
13+
completionHandler(nil)
14+
Task {
15+
let service = try getService()
16+
_ = try await service.getRealtimeSuggestedCode(editorContent: .init(invocation))
3617
}
3718
}
3819
}

EditorExtension/RejectSuggestionCommand.swift

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,10 @@ class RejectSuggestionCommand: NSObject, XCSourceEditorCommand, CommandType {
1010
with invocation: XCSourceEditorCommandInvocation,
1111
completionHandler: @escaping (Error?) -> Void
1212
) {
13-
switch UserDefaults.shared.value(for: \.suggestionPresentationMode) {
14-
case .comment:
15-
Task {
16-
do {
17-
try await (Task(timeout: 7) {
18-
let service = try getService()
19-
if let content = try await service.getSuggestionRejectedCode(
20-
editorContent: .init(invocation)
21-
) {
22-
invocation.accept(content)
23-
}
24-
completionHandler(nil)
25-
}.value)
26-
} catch is CancellationError {
27-
completionHandler(nil)
28-
} catch {
29-
completionHandler(error)
30-
}
31-
}
32-
case .floatingWidget:
33-
completionHandler(nil)
34-
Task {
35-
let service = try getService()
36-
_ = try await service.getSuggestionRejectedCode(editorContent: .init(invocation))
37-
}
13+
completionHandler(nil)
14+
Task {
15+
let service = try getService()
16+
_ = try await service.getSuggestionRejectedCode(editorContent: .init(invocation))
3817
}
3918
}
4019
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
public enum PresentationMode: Int, CaseIterable {
2-
case comment = 0
2+
case nearbyTextCursor = 0
33
case floatingWidget = 1
44
}

0 commit comments

Comments
 (0)