Skip to content

Commit a4bf72d

Browse files
committed
Pretty print GitHub Copilot logs
1 parent bcab207 commit a4bf72d

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

Pro

Submodule Pro updated from a47e180 to 2100084

Tool/Sources/GitHubCopilotService/CopilotLocalProcessServer.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ extension CopilotLocalProcessServer: LanguageServerProtocol.Server {
108108

109109
server.sendNotification(notif, completionHandler: completionHandler)
110110
}
111-
111+
112112
/// Cancel ongoing completion requests.
113113
public func cancelOngoingTasks() async {
114114
guard let server = wrappedServer, process.isRunning else {
115115
return
116116
}
117-
117+
118118
let task = Task { @MainActor in
119119
for id in self.ongoingCompletionRequestIDs {
120120
switch id {
@@ -126,7 +126,7 @@ extension CopilotLocalProcessServer: LanguageServerProtocol.Server {
126126
}
127127
self.ongoingCompletionRequestIDs = []
128128
}
129-
129+
130130
await task.value
131131
}
132132

@@ -200,32 +200,44 @@ extension CustomJSONRPCLanguageServer {
200200
block: @escaping (Error?) -> Void
201201
) -> Bool {
202202
let methodName = anyNotification.method
203+
let debugDescription = {
204+
if let params = anyNotification.params {
205+
let encoder = JSONEncoder()
206+
encoder.outputFormatting = .prettyPrinted
207+
if let jsonData = try? encoder.encode(params),
208+
let text = String(data: jsonData, encoding: .utf8)
209+
{
210+
return text
211+
}
212+
}
213+
return "N/A"
214+
}()
203215
switch methodName {
204216
case "window/logMessage":
205217
if UserDefaults.shared.value(for: \.gitHubCopilotVerboseLog) {
206218
Logger.gitHubCopilot
207-
.info("\(anyNotification.method): \(anyNotification.params.debugDescription)")
219+
.info("\(anyNotification.method): \(debugDescription)")
208220
}
209221
block(nil)
210222
return true
211223
case "LogMessage":
212224
if UserDefaults.shared.value(for: \.gitHubCopilotVerboseLog) {
213225
Logger.gitHubCopilot
214-
.info("\(anyNotification.method): \(anyNotification.params.debugDescription)")
226+
.info("\(anyNotification.method): \(debugDescription)")
215227
}
216-
block(nil)
228+
block(nil)//
217229
return true
218230
case "statusNotification":
219231
if UserDefaults.shared.value(for: \.gitHubCopilotVerboseLog) {
220232
Logger.gitHubCopilot
221-
.info("\(anyNotification.method): \(anyNotification.params.debugDescription)")
233+
.info("\(anyNotification.method): \(debugDescription)")
222234
}
223235
block(nil)
224236
return true
225237
case "featureFlagsNotification":
226238
if UserDefaults.shared.value(for: \.gitHubCopilotVerboseLog) {
227239
Logger.gitHubCopilot
228-
.info("\(anyNotification.method): \(anyNotification.params.debugDescription)")
240+
.info("\(anyNotification.method): \(debugDescription)")
229241
}
230242
block(nil)
231243
return true

0 commit comments

Comments
 (0)