Skip to content

Commit 373e818

Browse files
committed
Reopen document if it's not found in the language server
1 parent de131ed commit 373e818

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

Tool/Sources/GitHubCopilotService/GitHubCopilotExtension.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BuiltinExtension
22
import CopilotForXcodeKit
33
import Foundation
4+
import LanguageServerProtocol
45
import Logger
56
import Preferences
67
import Workspace
@@ -9,7 +10,7 @@ public final class GitHubCopilotExtension: BuiltinExtension {
910
public var suggestionServiceId: Preferences.BuiltInSuggestionFeatureProvider { .gitHubCopilot }
1011

1112
public let suggestionService: GitHubCopilotSuggestionService?
12-
13+
1314
private var extensionUsage = ExtensionUsage(
1415
isSuggestionServiceInUse: false,
1516
isChatServiceInUse: false
@@ -90,10 +91,23 @@ public final class GitHubCopilotExtension: BuiltinExtension {
9091
{ return }
9192

9293
Task {
94+
guard let content else { return }
95+
guard let service = await serviceLocator.getService(from: workspace) else { return }
9396
do {
94-
guard let content else { return }
95-
guard let service = await serviceLocator.getService(from: workspace) else { return }
96-
try await service.notifyChangeTextDocument(fileURL: documentURL, content: content, version: 0)
97+
try await service.notifyChangeTextDocument(
98+
fileURL: documentURL,
99+
content: content,
100+
version: 0
101+
)
102+
} catch let error as ServerError {
103+
switch error {
104+
case .serverError(-32602, _, _): // parameter incorrect
105+
Logger.gitHubCopilot.error(error.localizedDescription)
106+
// Reopen document if it's not found in the language server
107+
self.workspace(workspace, didOpenDocumentAt: documentURL)
108+
default:
109+
Logger.gitHubCopilot.error(error.localizedDescription)
110+
}
97111
} catch {
98112
Logger.gitHubCopilot.error(error.localizedDescription)
99113
}

0 commit comments

Comments
 (0)