fix: inlay hint assertion violation (#7164)

This PR fixes an assertion violation introduced in #7149 where the
monotonic progress assumption was violated by request cancellation.
This commit is contained in:
Marc Huisinga 2025-02-20 14:03:44 +01:00 committed by GitHub
parent 2eb478787f
commit 970732ea11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -126,10 +126,12 @@ def handleInlayHints (p : InlayHintParams) (s : InlayHintState) :
let timeSinceLastEditMs := timestamp - lastEditTimestamp
inlayHintEditDelayMs - timeSinceLastEditMs
let (snaps, _, isComplete) ← ctx.doc.cmdSnaps.getFinishedPrefixWithConsistentLatency editDelayMs.toUInt32 (cancelTk? := ctx.cancelTk.cancellationTask)
-- This cancellation check is crucial for the invariant `finishedSnaps >= oldFinishedSnaps` below.
RequestM.checkCancelled
let snaps := snaps.toArray
let finishedSnaps := snaps.size
let oldFinishedSnaps := s.oldFinishedSnaps
-- File processing is monotonic modulo `didChange` notifications.
-- File processing is monotonic modulo `didChange` notifications and cancellation.
assert! finishedSnaps >= oldFinishedSnaps
-- VS Code emits inlay hint requests *every time the user scrolls*. This is reasonably expensive,
-- so in addition to re-using old inlay hints from parts of the file that haven't been processed