@@ -62,6 +62,7 @@ module Development.IDE.Core.Shake(
6262 FileVersion (.. ),
6363 Priority (.. ),
6464 updatePositionMapping ,
65+ updatePositionMappingHelper ,
6566 deleteValue , recordDirtyKeys ,
6667 WithProgressFunc , WithIndefiniteProgressFunc ,
6768 ProgressEvent (.. ),
@@ -266,7 +267,7 @@ data ShakeExtras = ShakeExtras
266267 -- ^ Map from a text document version to a PositionMapping that describes how to map
267268 -- positions in a version of that document to positions in the latest version
268269 -- First mapping is delta from previous version and second one is an
269- -- accumulation of all previous mappings .
270+ -- accumulation to the current version .
270271 ,progress :: ProgressReporting
271272 ,ideTesting :: IdeTesting
272273 -- ^ Whether to enable additional lsp messages used by the test suite for checking invariants
@@ -443,7 +444,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
443444 `catch` (\ (_ :: IOException ) -> pure Nothing )
444445 atomicallyNamed " lastValueIO 2" $ do
445446 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
447+ Just . (v,) . addOldDelta del <$> mappingForVersion positionMapping file actual_version
447448
448449 -- We got a new stale value from the persistent rule, insert it in the map without affecting diagnostics
449450 alterValue new Nothing = Just (ValueWithDiagnostics new mempty ) -- If it wasn't in the map, give it empty diagnostics
@@ -459,7 +460,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
459460 Succeeded ver (fromDynamic -> Just v) ->
460461 atomicallyNamed " lastValueIO 5" $ Just . (v,) <$> mappingForVersion positionMapping file ver
461462 Stale del ver (fromDynamic -> Just v) ->
462- atomicallyNamed " lastValueIO 6" $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
463+ atomicallyNamed " lastValueIO 6" $ Just . (v,) . maybe id addOldDelta del <$> mappingForVersion positionMapping file ver
463464 Failed p | not p -> readPersistent
464465 _ -> pure Nothing
465466
@@ -1352,12 +1353,18 @@ updatePositionMapping IdeState{shakeExtras = ShakeExtras{positionMapping}} Versi
13521353 STM. focus (Focus. alter f) uri positionMapping
13531354 where
13541355 uri = toNormalizedUri _uri
1355- f = Just . f' . fromMaybe mempty
1356- f' mappingForUri = snd $
1357- -- Very important to use mapAccum here so that the tails of
1358- -- each mapping can be shared, otherwise quadratic space is
1359- -- used which is evident in long running sessions.
1360- EM. mapAccumRWithKey (\ acc _k (delta, _) -> let new = addDelta delta acc in (new, (delta, acc)))
1361- zeroMapping
1362- (EM. insert _version (shared_change, zeroMapping) mappingForUri)
1363- shared_change = mkDelta changes
1356+ f = Just . updatePositionMappingHelper _version changes . fromMaybe mempty
1357+
1358+
1359+ updatePositionMappingHelper ::
1360+ Int32
1361+ -> [TextDocumentContentChangeEvent ]
1362+ -> EnumMap Int32 (PositionDelta , PositionMapping )
1363+ -> EnumMap Int32 (PositionDelta , PositionMapping )
1364+ updatePositionMappingHelper ver changes mappingForUri = snd $
1365+ -- Very important to use mapAccum here so that the tails of
1366+ -- each mapping can be shared, otherwise quadratic space is
1367+ -- used which is evident in long running sessions.
1368+ EM. mapAccumRWithKey (\ acc _k (delta, _) -> let new = addOldDelta delta acc in (new, (delta, acc)))
1369+ zeroMapping
1370+ (EM. insert ver (mkDelta changes, zeroMapping) mappingForUri)
0 commit comments