Skip to content

Commit 62d0444

Browse files
committed
Bump GitHub Copilot language server
1 parent 73ff288 commit 62d0444

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

Core/Sources/HostApp/AccountSettings/GitHubCopilotView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct GitHubCopilotView: View {
158158
"node"
159159
)
160160
) {
161-
Text("Path to Node (v20.8+)")
161+
Text("Path to Node (v22.0+)")
162162
}
163163

164164
Text(

Tool/Sources/GitHubCopilotService/GitHubCopilotExtension.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import BuiltinExtension
22
import CopilotForXcodeKit
3+
import Dependencies
34
import Foundation
45
import LanguageServerProtocol
56
import Logger
67
import Preferences
8+
import Toast
79
import Workspace
810

911
public final class GitHubCopilotExtension: BuiltinExtension {
@@ -20,6 +22,8 @@ public final class GitHubCopilotExtension: BuiltinExtension {
2022
extensionUsage.isSuggestionServiceInUse || extensionUsage.isChatServiceInUse
2123
}
2224

25+
@Dependency(\.toastController) var toast
26+
2327
let workspacePool: WorkspacePool
2428

2529
let serviceLocator: ServiceLocatorType
@@ -49,6 +53,16 @@ public final class GitHubCopilotExtension: BuiltinExtension {
4953
let content = try String(contentsOf: documentURL, encoding: .utf8)
5054
guard let service = await serviceLocator.getService(from: workspace) else { return }
5155
try await service.notifyOpenTextDocument(fileURL: documentURL, content: content)
56+
} catch let error as ServerError {
57+
let e = GitHubCopilotError.languageServerError(error)
58+
Logger.gitHubCopilot.error(e.localizedDescription)
59+
60+
switch error {
61+
case .serverUnavailable, .serverError:
62+
toast.toast(content: e.localizedDescription, type: .error, duration: 10.0)
63+
default:
64+
break
65+
}
5266
} catch {
5367
Logger.gitHubCopilot.error(error.localizedDescription)
5468
}
@@ -295,7 +309,7 @@ extension GitHubCopilotExtension {
295309
var id: String
296310
var capabilities: Capability
297311
}
298-
312+
299313
struct Body: Decodable {
300314
var data: [Model]
301315
}

Tool/Sources/GitHubCopilotService/GitHubCopilotWorkspacePlugin.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import Dependencies
12
import Foundation
23
import Logger
3-
import Workspace
44
import Toast
5-
import Dependencies
5+
import Workspace
66

77
public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
88
enum Error: Swift.Error, LocalizedError {
@@ -14,7 +14,7 @@ public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
1414
}
1515
}
1616
}
17-
17+
1818
@Dependency(\.toast) var toast
1919

2020
let installationManager = GitHubCopilotInstallationManager()
@@ -32,6 +32,10 @@ public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
3232
return nil
3333
} catch {
3434
Logger.gitHubCopilot.error("Failed to create GitHub Copilot service: \(error)")
35+
toast(
36+
"Failed to start GitHub Copilot language server: \(error.localizedDescription)",
37+
.error
38+
)
3539
return nil
3640
}
3741
}
@@ -74,7 +78,7 @@ public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
7478
}
7579
}
7680
}
77-
81+
7882
@GitHubCopilotSuggestionActor
7983
func updateLanguageServerIfPossible() async {
8084
guard !GitHubCopilotInstallationManager.isInstalling else { return }

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotInstallationManager.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ public struct GitHubCopilotInstallationManager {
66
public private(set) static var isInstalling = false
77

88
static var downloadURL: URL {
9-
let commitHash = "18f485d892b56b311fd752039d6977333ebc2a0f"
9+
let commitHash = "f89e977c87180519ba3b942200e3d05b17b1e2fc"
1010
let link = "https://github.com/github/copilot.vim/archive/\(commitHash).zip"
1111
return URL(string: link)!
1212
}
1313

1414
/// The GitHub's version has quite a lot of changes about `watchedFiles` since the following
1515
/// commit.
1616
/// https://github.com/github/CopilotForXcode/commit/a50045aa3ab3b7d532cadf40c4c10bed32f81169#diff-678798cf677bcd1ce276809cfccd33da9ff594b1b0c557180210a4ed2bd27ffa
17-
static let latestSupportedVersion = "1.48.0"
17+
static let latestSupportedVersion = "1.57.0"
1818
static let minimumSupportedVersion = "1.32.0"
1919

2020
public init() {}
@@ -151,7 +151,15 @@ public struct GitHubCopilotInstallationManager {
151151
return
152152
}
153153

154-
let lspURL = gitFolderURL.appendingPathComponent("dist")
154+
let lspURL = {
155+
let caseA = gitFolderURL.appendingPathComponent("dist")
156+
if FileManager.default.fileExists(atPath: caseA.path) {
157+
return caseA
158+
}
159+
return gitFolderURL
160+
.appendingPathComponent("copilot-language-server")
161+
.appendingPathComponent("dist")
162+
}()
155163
let copilotURL = urls.executableURL.appendingPathComponent("copilot")
156164

157165
if !FileManager.default.fileExists(atPath: copilotURL.path) {

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ enum GitHubCopilotError: Error, LocalizedError {
8383
case let .clientDataUnavailable(error):
8484
return "Language server error: Client data unavailable: \(error)"
8585
case .serverUnavailable:
86-
return "Language server error: Server unavailable, please make sure that:\n1. The path to node is correctly set.\n2. The node is not a shim executable.\n3. the node version is high enough."
86+
return "Language server error: Server unavailable, please make sure that:\n1. The path to node is correctly set.\n2. The node is not a shim executable.\n3. the node version is high enough (v22.0+)."
8787
case .missingExpectedParameter:
8888
return "Language server error: Missing expected parameter"
8989
case .missingExpectedResult:
@@ -523,11 +523,23 @@ public final class GitHubCopilotService: GitHubCopilotBaseService,
523523
// And sometimes the language server's content was not up to date and may generate
524524
// weird result when the cursor position exceeds the line.
525525
let task = Task { @GitHubCopilotSuggestionActor in
526-
try await notifyChangeTextDocument(
527-
fileURL: fileURL,
528-
content: content,
529-
version: 1
530-
)
526+
do {
527+
try await notifyChangeTextDocument(
528+
fileURL: fileURL,
529+
content: content,
530+
version: 1
531+
)
532+
} catch let error as ServerError {
533+
switch error {
534+
case .serverUnavailable:
535+
throw SuggestionServiceError
536+
.notice(GitHubCopilotError.languageServerError(error))
537+
default:
538+
throw error
539+
}
540+
} catch {
541+
throw error
542+
}
531543

532544
do {
533545
try Task.checkCancellation()

0 commit comments

Comments
 (0)