Skip to content

Commit ee2bbef

Browse files
committed
Merge branch 'feature/codeium-1.2.25' into develop
2 parents f28d836 + f21722c commit ee2bbef

5 files changed

Lines changed: 107 additions & 9 deletions

File tree

Core/Sources/CodeiumService/CodeiumInstallationManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Terminal
33

44
public struct CodeiumInstallationManager {
55
private static var isInstalling = false
6-
static let latestSupportedVersion = "1.2.17"
6+
static let latestSupportedVersion = "1.2.25"
77

88
public init() {}
99

Core/Sources/CodeiumService/CodeiumRequest.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,25 @@ enum CodeiumRequest {
4848
}
4949
}
5050

51-
struct AcceptCompletion: CodeiumRequestType {
52-
struct Response: Codable {
53-
var state: State
54-
var completionItems: [CodeiumCompletionItem]?
51+
struct CancelRequest: CodeiumRequestType {
52+
struct Response: Codable {}
53+
54+
struct RequestBody: Codable {
55+
var request_id: UInt64
56+
var session_id: String
5557
}
5658

59+
var requestBody: RequestBody
60+
61+
func makeURLRequest(server: String) -> URLRequest {
62+
let data = (try? JSONEncoder().encode(requestBody)) ?? Data()
63+
return assembleURLRequest(server: server, method: "CancelRequest", body: data)
64+
}
65+
}
66+
67+
struct AcceptCompletion: CodeiumRequestType {
68+
struct Response: Codable {}
69+
5770
struct RequestBody: Codable {
5871
var metadata: Metadata
5972
var completion_id: String

Core/Sources/CodeiumService/CodeiumService.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ extension CodeiumSuggestionService: CodeiumSuggestionServiceType {
257257
)
258258
}
259259
))
260-
260+
261261
if request.requestBody.metadata.request_id <= cancellationCounter {
262262
throw CancellationError()
263263
}
264264

265265
let result = try await (try await setupServerIfNeeded()).sendRequest(request)
266-
266+
267267
if request.requestBody.metadata.request_id <= cancellationCounter {
268268
throw CancellationError()
269269
}
@@ -292,8 +292,16 @@ extension CodeiumSuggestionService: CodeiumSuggestionServiceType {
292292
)
293293
} ?? []
294294
}
295-
295+
296296
public func cancelRequest() async {
297+
Task {
298+
try await server?.sendRequest(
299+
CodeiumRequest.CancelRequest(requestBody: .init(
300+
request_id: requestCounter,
301+
session_id: CodeiumSuggestionService.sessionId
302+
))
303+
)
304+
}
297305
cancellationCounter = requestCounter
298306
}
299307

@@ -326,7 +334,7 @@ extension CodeiumSuggestionService: CodeiumSuggestionServiceType {
326334
public func notifyCloseTextDocument(fileURL: URL) async throws {
327335
await openedDocumentPool.closeDocument(url: fileURL)
328336
}
329-
337+
330338
public func terminate() {
331339
server?.terminate()
332340
server = nil
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import CodeiumService
2+
import GitHubCopilotService
3+
import Logger
4+
5+
public struct DependencyUpdater {
6+
public init() {}
7+
8+
public func update() {
9+
Task {
10+
await withTaskGroup(of: Void.self) { taskGroup in
11+
let gitHubCopilot = GitHubCopilotInstallationManager()
12+
switch gitHubCopilot.checkInstallation() {
13+
case .notInstalled: break
14+
case .installed: break
15+
case .unsupported: break
16+
case .outdated:
17+
taskGroup.addTask {
18+
do {
19+
for try await step in gitHubCopilot.installLatestVersion() {
20+
let state = {
21+
switch step {
22+
case .downloading:
23+
return "Downloading"
24+
case .uninstalling:
25+
return "Uninstalling old version"
26+
case .decompressing:
27+
return "Decompressing"
28+
case .done:
29+
return "Done"
30+
}
31+
}()
32+
Logger.service
33+
.error("Update GitHub Copilot language server: \(state)")
34+
}
35+
} catch {
36+
Logger.service.error(
37+
"Update GitHub Copilot language server: \(error.localizedDescription)"
38+
)
39+
}
40+
}
41+
}
42+
let codeium = CodeiumInstallationManager()
43+
switch codeium.checkInstallation() {
44+
case .notInstalled: break
45+
case .installed: break
46+
case .unsupported: break
47+
case .outdated:
48+
taskGroup.addTask {
49+
do {
50+
for try await step in codeium.installLatestVersion() {
51+
let state = {
52+
switch step {
53+
case .downloading:
54+
return "Downloading"
55+
case .uninstalling:
56+
return "Uninstalling old version"
57+
case .decompressing:
58+
return "Decompressing"
59+
case .done:
60+
return "Done"
61+
}
62+
}()
63+
Logger.service.error("Update Codeium language server: \(state)")
64+
}
65+
} catch {
66+
Logger.service.error(
67+
"Update Codeium language server: \(error.localizedDescription)"
68+
)
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+

ExtensionService/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
4242
Logger.service.info("XPC Service started.")
4343
NSApp.setActivationPolicy(.accessory)
4444
buildStatusBarMenu()
45+
DependencyUpdater().update()
4546
Task {
4647
do {
4748
try await ServiceUpdateMigrator().migrate()

0 commit comments

Comments
 (0)