Skip to content

Commit 30fb56c

Browse files
committed
Add the boost QoS hack that doesn't really make any change
https://developer.apple.com/forums/thread/682769
1 parent 62a15ff commit 30fb56c

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

Copilot for Xcode/App.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import Client
12
import SwiftUI
2-
import XPCShared
33
import UpdateChecker
4+
import XPCShared
45

56
@main
67
struct CopilotForXcodeApp: App {
@@ -11,6 +12,10 @@ struct CopilotForXcodeApp: App {
1112
.preferredColorScheme(.dark)
1213
.onAppear {
1314
UserDefaults.setupDefaultSettings()
15+
Task {
16+
let service = try getService()
17+
await service.boostQoS()
18+
}
1419
}
1520
.environment(\.updateChecker, UpdateChecker(hostBundle: Bundle.main))
1621
}
@@ -21,7 +26,7 @@ struct CopilotForXcodeApp: App {
2126
var isPreview: Bool { ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" }
2227

2328
struct UpdateCheckerKey: EnvironmentKey {
24-
static var defaultValue: UpdateChecker = UpdateChecker(hostBundle: nil)
29+
static var defaultValue: UpdateChecker = .init(hostBundle: nil)
2530
}
2631

2732
extension EnvironmentValues {
@@ -30,5 +35,3 @@ extension EnvironmentValues {
3035
set { self[UpdateCheckerKey.self] = newValue }
3136
}
3237
}
33-
34-

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import CopilotModel
22
import Foundation
33
import XPCShared
4+
import Logger
45

56
public struct AsyncXPCService {
67
public var connection: NSXPCConnection { service.connection }
@@ -10,6 +11,15 @@ public struct AsyncXPCService {
1011
self.service = service
1112
}
1213

14+
public func boostQoS() async {
15+
let service = connection.remoteObjectProxyWithErrorHandler {
16+
Logger.client.error($0)
17+
} as! XPCServiceProtocol
18+
service.boostQoS {
19+
// never reply
20+
}
21+
}
22+
1323
public func checkStatus() async throws -> CopilotStatus {
1424
try await withXPCServiceConnected(connection: connection) {
1525
service, continuation in
@@ -170,23 +180,23 @@ public struct AsyncXPCService {
170180
}
171181
}
172182
}
173-
183+
174184
public func explainSelection(editorContent: EditorContent) async throws -> UpdatedContent? {
175185
try await suggestionRequest(
176186
connection,
177187
editorContent,
178188
{ $0.explainSelection }
179189
)
180190
}
181-
191+
182192
public func chatWithSelection(editorContent: EditorContent) async throws -> UpdatedContent? {
183193
try await suggestionRequest(
184194
connection,
185195
editorContent,
186196
{ $0.chatWithSelection }
187197
)
188198
}
189-
199+
190200
public func promptToCode(editorContent: EditorContent) async throws -> UpdatedContent? {
191201
try await suggestionRequest(
192202
connection,

Core/Sources/Service/XPCService.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ var workspaces = [URL: Workspace]()
2020
var inflightRealtimeSuggestionsTasks = Set<Task<Void, Never>>()
2121

2222
public class XPCService: NSObject, XPCServiceProtocol {
23+
var boostQoS = [Any]()
24+
25+
public func boostQoS(withReply reply: @escaping () -> Void) {
26+
boostQoS.append(reply)
27+
}
28+
2329
// MARK: - Service
2430

2531
public func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void) {

Core/Sources/XPCShared/XPCServiceProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Foundation
33

44
@objc(XPCServiceProtocol)
55
public protocol XPCServiceProtocol {
6+
func boostQoS(withReply reply: @escaping () -> Void)
67
func checkStatus(withReply reply: @escaping (String?, Error?) -> Void)
78
func signInInitiate(withReply reply: @escaping (String?, String?, Error?) -> Void)
89
func signInConfirm(

EditorExtension/SourceEditorExtension.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SourceEditorExtension: NSObject, XCSourceEditorExtension {
2929
try await Task.sleep(nanoseconds: 1_000_000_000)
3030
let service = try getService()
3131
_ = try await service.checkStatus()
32+
await service.boostQoS()
3233
}
3334
#endif
3435
}

0 commit comments

Comments
 (0)