Skip to content

Commit b60acde

Browse files
authored
Merge pull request #1406 from ahoppen/cancellation-logging-scope
Set the logging scope for notification handling one level higher so it’s also set for cancel notifications
2 parents 9d970e4 + 63c1442 commit b60acde

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -532,26 +532,25 @@ private nonisolated(unsafe) var notificationIDForLogging = AtomicUInt32(initialV
532532

533533
extension SourceKitLSPServer: MessageHandler {
534534
public nonisolated func handle(_ params: some NotificationType) {
535-
if let params = params as? CancelRequestNotification {
536-
// Request cancellation needs to be able to overtake any other message we
537-
// are currently handling. Ordering is not important here. We thus don't
538-
// need to execute it on `messageHandlingQueue`.
539-
self.cancelRequest(params)
540-
}
541-
542535
let notificationID = notificationIDForLogging.fetchAndIncrement()
536+
withLoggingScope("notification-\(notificationID % 100)") {
537+
if let params = params as? CancelRequestNotification {
538+
// Request cancellation needs to be able to overtake any other message we
539+
// are currently handling. Ordering is not important here. We thus don't
540+
// need to execute it on `messageHandlingQueue`.
541+
self.cancelRequest(params)
542+
}
543543

544-
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "message-handling")
545-
.makeSignposter()
546-
let signpostID = signposter.makeSignpostID()
547-
let state = signposter.beginInterval("Notification", id: signpostID, "\(type(of: params))")
548-
messageHandlingQueue.async(metadata: MessageHandlingDependencyTracker(params)) {
549-
signposter.emitEvent("Start handling", id: signpostID)
544+
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "message-handling")
545+
.makeSignposter()
546+
let signpostID = signposter.makeSignpostID()
547+
let state = signposter.beginInterval("Notification", id: signpostID, "\(type(of: params))")
548+
messageHandlingQueue.async(metadata: MessageHandlingDependencyTracker(params)) {
549+
signposter.emitEvent("Start handling", id: signpostID)
550550

551-
// Only use the last two digits of the notification ID for the logging scope to avoid creating too many scopes.
552-
// See comment in `withLoggingScope`.
553-
// The last 2 digits should be sufficient to differentiate between multiple concurrently running notifications.
554-
await withLoggingScope("notification-\(notificationID % 100)") {
551+
// Only use the last two digits of the notification ID for the logging scope to avoid creating too many scopes.
552+
// See comment in `withLoggingScope`.
553+
// The last 2 digits should be sufficient to differentiate between multiple concurrently running notifications.
555554
await self.handleImpl(params)
556555
signposter.endInterval("Notification", state, "Done")
557556
}
@@ -2430,7 +2429,7 @@ fileprivate extension RequestID {
24302429
var numericValue: Int {
24312430
switch self {
24322431
case .number(let number): return number
2433-
case .string(let string): return Int(string) ?? string.hashValue
2432+
case .string(let string): return Int(string) ?? abs(string.hashValue)
24342433
}
24352434
}
24362435
}

0 commit comments

Comments
 (0)