File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Sources/SourceKitLSP/Swift Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -110,12 +110,6 @@ actor DiagnosticReportManager {
110
110
let dict = try await self . sourcekitd. send ( skreq, fileContents: snapshot. text)
111
111
112
112
try Task . checkCancellation ( )
113
- guard ( try ? documentManager. latestSnapshot ( snapshot. uri) . id) == snapshot. id else {
114
- // Check that the document wasn't modified while we were getting diagnostics. This could happen because we are
115
- // calling `fullDocumentDiagnosticReport` from `publishDiagnosticsIfNeeded` outside of `messageHandlingQueue`
116
- // and thus a concurrent edit is possible while we are waiting for the sourcekitd request to return a result.
117
- throw ResponseError . unknown ( " Document was modified while loading diagnostics " )
118
- }
119
113
120
114
let diagnostics : [ Diagnostic ] =
121
115
dict [ keys. diagnostics] ? . compactMap ( { diag in
Original file line number Diff line number Diff line change @@ -436,6 +436,20 @@ extension SwiftLanguageServer {
436
436
for: snapshot,
437
437
buildSettings: buildSettings
438
438
)
439
+ let latestSnapshotID = try ? await documentManager. latestSnapshot ( snapshot. uri) . id
440
+ if latestSnapshotID != snapshot. id {
441
+ // Check that the document wasn't modified while we were getting diagnostics. This could happen because we are
442
+ // calling `publishDiagnosticsIfNeeded` outside of `messageHandlingQueue` and thus a concurrent edit is
443
+ // possible while we are waiting for the sourcekitd request to return a result.
444
+ logger. log (
445
+ """
446
+ Document was modified while loading diagnostics. \
447
+ Loaded diagnostics for \( snapshot. id. version, privacy: . public) , \
448
+ latest snapshot is \( ( latestSnapshotID? . version) . map ( String . init) ?? " <nil> " , privacy: . public)
449
+ """
450
+ )
451
+ throw CancellationError ( )
452
+ }
439
453
440
454
await sourceKitServer. sendNotificationToClient (
441
455
PublishDiagnosticsNotification (
You can’t perform that action at this time.
0 commit comments