Skip to content

Commit 62613e9

Browse files
committed
Fix that the GitHub Copilot language server was not terminating when the workspace closed
1 parent 3f328dd commit 62613e9

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

Tool/Sources/GitHubCopilotService/GitHubCopilotExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ final class ServiceLocator {
141141
guard let workspace = workspacePool.workspaces[workspace.workspaceURL],
142142
let plugin = workspace.plugin(for: GitHubCopilotWorkspacePlugin.self)
143143
else { return nil }
144-
return plugin.gitHubCopilotService
144+
return await plugin.gitHubCopilotService
145145
}
146146
}
147147

Tool/Sources/GitHubCopilotService/GitHubCopilotWorkspacePlugin.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Logger
33
import Workspace
44

55
public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
6-
var _gitHubCopilotService: GitHubCopilotService?
6+
private var _gitHubCopilotService: GitHubCopilotService?
7+
@GitHubCopilotSuggestionActor
78
var gitHubCopilotService: GitHubCopilotService? {
89
if let service = _gitHubCopilotService { return service }
910
do {
@@ -15,21 +16,27 @@ public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
1516
}
1617

1718
deinit {
18-
if let gitHubCopilotService {
19-
Task { await gitHubCopilotService.terminate() }
19+
if let _gitHubCopilotService {
20+
Task { await _gitHubCopilotService.terminate() }
2021
}
2122
}
2223

24+
@GitHubCopilotSuggestionActor
2325
func createGitHubCopilotService() throws -> GitHubCopilotService {
2426
let newService = try GitHubCopilotService(projectRootURL: projectRootURL)
2527
_gitHubCopilotService = newService
28+
newService.localProcessServer?.terminationHandler = { [weak self] in
29+
Logger.gitHubCopilot.error("GitHub Copilot language server terminated")
30+
self?.terminate()
31+
}
2632
Task {
2733
try await Task.sleep(nanoseconds: 1_000_000_000)
2834
finishLaunchingService()
2935
}
3036
return newService
3137
}
3238

39+
@GitHubCopilotSuggestionActor
3340
func finishLaunchingService() {
3441
guard let workspace, let _gitHubCopilotService else { return }
3542
Task {

Tool/Sources/GitHubCopilotService/LanguageServer/CopilotLocalProcessServer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class CopilotLocalProcessServer {
8484
get { return wrappedServer?.logMessages ?? false }
8585
set { wrappedServer?.logMessages = newValue }
8686
}
87+
88+
func terminate() {
89+
process.terminate()
90+
}
8791
}
8892

8993
extension CopilotLocalProcessServer: LanguageServerProtocol.Server {

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public class GitHubCopilotBaseService {
9595
let projectRootURL: URL
9696
var server: GitHubCopilotLSP
9797
var localProcessServer: CopilotLocalProcessServer?
98+
99+
deinit {
100+
localProcessServer?.terminate()
101+
}
98102

99103
init(designatedServer: GitHubCopilotLSP) {
100104
projectRootURL = URL(fileURLWithPath: "/")

Tool/Sources/Workspace/Workspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class Workspace {
7474
public let openedFileRecoverableStorage: OpenedFileRecoverableStorage
7575
public private(set) var lastLastUpdateTime = Environment.now()
7676
public var isExpired: Bool {
77-
Environment.now().timeIntervalSince(lastLastUpdateTime) > 60 * 60 * 1
77+
Environment.now().timeIntervalSince(lastLastUpdateTime) > 30 * 60 * 1
7878
}
7979

8080
public private(set) var filespaces = [URL: Filespace]()

0 commit comments

Comments
 (0)