@@ -62,6 +62,7 @@ module Development.IDE.Core.Shake(
62
62
FileVersion (.. ),
63
63
Priority (.. ),
64
64
updatePositionMapping ,
65
+ updatePositionMappingHelper ,
65
66
deleteValue , recordDirtyKeys ,
66
67
WithProgressFunc , WithIndefiniteProgressFunc ,
67
68
ProgressEvent (.. ),
@@ -266,7 +267,7 @@ data ShakeExtras = ShakeExtras
266
267
-- ^ Map from a text document version to a PositionMapping that describes how to map
267
268
-- positions in a version of that document to positions in the latest version
268
269
-- First mapping is delta from previous version and second one is an
269
- -- accumulation of all previous mappings .
270
+ -- accumulation to the current version .
270
271
,progress :: ProgressReporting
271
272
,ideTesting :: IdeTesting
272
273
-- ^ 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
443
444
`catch` (\ (_ :: IOException ) -> pure Nothing )
444
445
atomicallyNamed " lastValueIO 2" $ do
445
446
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
447
448
448
449
-- We got a new stale value from the persistent rule, insert it in the map without affecting diagnostics
449
450
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
459
460
Succeeded ver (fromDynamic -> Just v) ->
460
461
atomicallyNamed " lastValueIO 5" $ Just . (v,) <$> mappingForVersion positionMapping file ver
461
462
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
463
464
Failed p | not p -> readPersistent
464
465
_ -> pure Nothing
465
466
@@ -1352,12 +1353,18 @@ updatePositionMapping IdeState{shakeExtras = ShakeExtras{positionMapping}} Versi
1352
1353
STM. focus (Focus. alter f) uri positionMapping
1353
1354
where
1354
1355
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