Skip to content

Commit 59672e9

Browse files
committed
Log when a sourcekitd request gets cancelled
I saw a failure in CI where a sourcekitd diagnostic request got cancelled without an LSP cancellation request. I am suspecting that there is some implicit cancellation going on in sourcekitd despite `key.cancel_builds: 0`, which doesn’t make sense to me. Adding some explicit logging to sourcekit-lsp to check if we cancel the request for some reason.
1 parent 14775e8 commit 59672e9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Sources/SourceKitD/DynamicallyLoadedSourceKitD.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extension sourcekitd_api_values: @unchecked Sendable {}
3131
/// Users of this class should not call the api functions `initialize`, `shutdown`, or
3232
/// `set_notification_handler`, which are global state managed internally by this class.
3333
public actor DynamicallyLoadedSourceKitD: SourceKitD {
34-
3534
/// The path to the sourcekitd dylib.
3635
public let path: AbsolutePath
3736

@@ -142,6 +141,16 @@ public actor DynamicallyLoadedSourceKitD: SourceKitD {
142141
}
143142
}
144143

144+
public nonisolated func logRequestCancellation(request: SKDRequestDictionary) {
145+
// We don't need to log which request has been cancelled because we can associate the cancellation log message with
146+
// the send message via the log
147+
logger.info(
148+
"""
149+
Cancelling sourcekitd request:
150+
\(request.forLogging)
151+
"""
152+
)
153+
}
145154
}
146155

147156
struct WeakSKDNotificationHandler: Sendable {

Sources/SourceKitD/SourceKitD.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public protocol SourceKitD: AnyObject, Sendable {
5959
/// This log call is issued during normal operation. It is acceptable for the logger to truncate the log message
6060
/// to achieve good performance.
6161
func log(response: SKDResponse)
62+
63+
/// Log that the given request has been cancelled.
64+
func logRequestCancellation(request: SKDRequestDictionary)
6265
}
6366

6467
public enum SKDError: Error, Equatable {
@@ -97,6 +100,7 @@ extension SourceKitD {
97100
return handle
98101
} cancel: { handle in
99102
if let handle {
103+
logRequestCancellation(request: req)
100104
api.cancel_request(handle)
101105
}
102106
}

Tests/SourceKitDTests/SourceKitDRegistryTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ final class FakeSourceKitD: SourceKitD {
8080
public func log(request: SKDRequestDictionary) {}
8181
public func log(response: SKDResponse) {}
8282
public func log(crashedRequest: SKDRequestDictionary, fileContents: String?) {}
83+
public func logRequestCancellation(request: SKDRequestDictionary) {}
8384
}

0 commit comments

Comments
 (0)