Skip to content

Log when a sourcekitd request gets cancelled #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sources/SourceKitD/DynamicallyLoadedSourceKitD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extension sourcekitd_api_values: @unchecked Sendable {}
/// Users of this class should not call the api functions `initialize`, `shutdown`, or
/// `set_notification_handler`, which are global state managed internally by this class.
public actor DynamicallyLoadedSourceKitD: SourceKitD {

/// The path to the sourcekitd dylib.
public let path: AbsolutePath

Expand Down Expand Up @@ -142,6 +141,16 @@ public actor DynamicallyLoadedSourceKitD: SourceKitD {
}
}

public nonisolated func logRequestCancellation(request: SKDRequestDictionary) {
// We don't need to log which request has been cancelled because we can associate the cancellation log message with
// the send message via the log
logger.info(
"""
Cancelling sourcekitd request:
\(request.forLogging)
"""
)
}
}

struct WeakSKDNotificationHandler: Sendable {
Expand Down
4 changes: 4 additions & 0 deletions Sources/SourceKitD/SourceKitD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public protocol SourceKitD: AnyObject, Sendable {
/// This log call is issued during normal operation. It is acceptable for the logger to truncate the log message
/// to achieve good performance.
func log(response: SKDResponse)

/// Log that the given request has been cancelled.
func logRequestCancellation(request: SKDRequestDictionary)
}

public enum SKDError: Error, Equatable {
Expand Down Expand Up @@ -97,6 +100,7 @@ extension SourceKitD {
return handle
} cancel: { handle in
if let handle {
logRequestCancellation(request: req)
api.cancel_request(handle)
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/SourceKitDTests/SourceKitDRegistryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ final class FakeSourceKitD: SourceKitD {
public func log(request: SKDRequestDictionary) {}
public func log(response: SKDResponse) {}
public func log(crashedRequest: SKDRequestDictionary, fileContents: String?) {}
public func logRequestCancellation(request: SKDRequestDictionary) {}
}