11import BuiltinExtension
22import CopilotForXcodeKit
33import Foundation
4+ import LanguageServerProtocol
45import Logger
56import Preferences
67import 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