@@ -6,6 +6,7 @@ import LanguageServerProtocol
66import Logger
77import Preferences
88import SuggestionBasic
9+ import XcodeInspector
910
1011public 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
3941protocol 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
592602extension 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