Skip to content

Commit 4256e7f

Browse files
committed
Fix positionMapping in stale data
1 parent 74466a9 commit 4256e7f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ghcide/src/Development/IDE/Core/PositionMapping.hs

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ mkDelta cs = foldl' applyChange idDelta cs
123123
addDelta :: PositionDelta -> PositionMapping -> PositionMapping
124124
addDelta delta (PositionMapping pm) = PositionMapping (composeDelta delta pm)
125125

126+
-- | Add a old delta onto a Mapping k n to make a Mapping (k - 1) n
127+
addOldDelta :: PositionDelta -> PositionMapping -> PositionMapping
128+
addOldDelta delta (PositionMapping pm) = PositionMapping (composeDelta pm delta )
129+
126130
-- TODO: We currently ignore the right hand side (if there is only text), as
127131
-- that was what was done with lsp* 1.6 packages
128132
applyChange :: PositionDelta -> TextDocumentContentChangeEvent -> PositionDelta

ghcide/src/Development/IDE/Core/Shake.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
443443
`catch` (\(_ :: IOException) -> pure Nothing)
444444
atomicallyNamed "lastValueIO 2" $ do
445445
STM.focus (Focus.alter (alterValue $ Stale (Just del) actual_version (toDyn v))) (toKey k file) state
446-
Just . (v,) . addDelta del <$> mappingForVersion positionMapping file actual_version
446+
Just . (v,) . addOldDelta del <$> mappingForVersion positionMapping file actual_version
447447

448448
-- We got a new stale value from the persistent rule, insert it in the map without affecting diagnostics
449449
alterValue new Nothing = Just (ValueWithDiagnostics new mempty) -- If it wasn't in the map, give it empty diagnostics
@@ -459,7 +459,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
459459
Succeeded ver (fromDynamic -> Just v) ->
460460
atomicallyNamed "lastValueIO 5" $ Just . (v,) <$> mappingForVersion positionMapping file ver
461461
Stale del ver (fromDynamic -> Just v) ->
462-
atomicallyNamed "lastValueIO 6" $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
462+
atomicallyNamed "lastValueIO 6" $ Just . (v,) . maybe id addOldDelta del <$> mappingForVersion positionMapping file ver
463463
Failed p | not p -> readPersistent
464464
_ -> pure Nothing
465465

0 commit comments

Comments
 (0)