Skip to content

Commit ddb97d2

Browse files
committed
Update info
1 parent 97a866c commit ddb97d2

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotRequest.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import JSONRPC
33
import LanguageServerProtocol
44
import SuggestionBasic
5+
import XcodeInspector
56

67
struct GitHubCopilotDoc: Codable {
78
var source: String
@@ -55,6 +56,8 @@ enum GitHubCopilotChatSource: String, Codable {
5556

5657
enum GitHubCopilotRequest {
5758
struct SetEditorInfo: GitHubCopilotRequestType {
59+
let xcodeVersion: String
60+
5861
struct Response: Codable {}
5962

6063
var networkProxy: JSONValue? {
@@ -142,12 +145,13 @@ enum GitHubCopilotRequest {
142145
"name": "vscode",
143146
"version": "1.89.1",
144147
]) : .hash([
145-
"name": "xcode",
146-
"version": "",
148+
"name": "Xcode",
149+
"version": .string(xcodeVersion),
147150
]),
148151
"editorPluginInfo": .hash([
149152
"name": "Copilot for Xcode",
150-
"version": "",
153+
"version": .string(Bundle.main
154+
.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""),
151155
]),
152156
]
153157

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import LanguageServerProtocol
66
import Logger
77
import Preferences
88
import SuggestionBasic
9+
import XcodeInspector
910

1011
public protocol GitHubCopilotAuthServiceType {
1112
func checkStatus() async throws -> GitHubCopilotAccountStatus
@@ -34,6 +35,7 @@ public protocol GitHubCopilotSuggestionServiceType {
3435
func notifySaveTextDocument(fileURL: URL) async throws
3536
func cancelRequest() async
3637
func terminate() async
38+
func cancelOngoingTask(workDoneToken: String) async
3739
}
3840

3941
protocol GitHubCopilotLSP {
@@ -255,11 +257,15 @@ public class GitHubCopilotBaseService {
255257
let notifications = NotificationCenter.default
256258
.notifications(named: .gitHubCopilotShouldRefreshEditorInformation)
257259
Task { [weak self] in
258-
_ = try? await server.sendRequest(GitHubCopilotRequest.SetEditorInfo())
260+
_ = try? await server.sendRequest(
261+
GitHubCopilotRequest.SetEditorInfo(xcodeVersion: xcodeVersion() ?? "16.0")
262+
)
259263

260264
for await _ in notifications {
261265
guard self != nil else { return }
262-
_ = try? await server.sendRequest(GitHubCopilotRequest.SetEditorInfo())
266+
_ = try? await server.sendRequest(
267+
GitHubCopilotRequest.SetEditorInfo(xcodeVersion: xcodeVersion() ?? "16.0")
268+
)
263269
}
264270
}
265271
}
@@ -587,6 +593,10 @@ public final class GitHubCopilotService: GitHubCopilotBaseService,
587593
public func terminate() async {
588594
// automatically handled
589595
}
596+
597+
public func cancelOngoingTask(workDoneToken: String) async {
598+
await localProcessServer?.cancelOngoingTask(workDoneToken: workDoneToken)
599+
}
590600
}
591601

592602
extension InitializingServer: GitHubCopilotLSP {
@@ -606,3 +616,30 @@ extension InitializingServer: GitHubCopilotLSP {
606616
}
607617
}
608618

619+
private func xcodeVersion() async -> String? {
620+
if let xcode = await XcodeInspector.shared.safe.latestActiveXcode {
621+
return xcode.version
622+
}
623+
let process = Process()
624+
process.executableURL = URL(fileURLWithPath: "/usr/bin/xcrun")
625+
process.arguments = ["xcodebuild", "-version"]
626+
627+
let pipe = Pipe()
628+
process.standardOutput = pipe
629+
630+
do {
631+
try process.run()
632+
} catch {
633+
print("Error running xcrun xcodebuild: \(error)")
634+
return nil
635+
}
636+
637+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
638+
guard let output = String(data: data, encoding: .utf8) else {
639+
return nil
640+
}
641+
642+
let lines = output.split(separator: "\n")
643+
return lines.first?.split(separator: " ").last.map(String.init)
644+
}
645+

0 commit comments

Comments
 (0)