@@ -198,7 +198,7 @@ data ShakeExtras = ShakeExtras
198
198
,publishedDiagnostics :: STM. Map NormalizedUri [Diagnostic ]
199
199
-- ^ This represents the set of diagnostics that we have published.
200
200
-- Due to debouncing not every change might get published.
201
- ,positionMapping :: Var ( HMap. HashMap NormalizedUri (Map TextDocumentVersion (PositionDelta , PositionMapping ) ))
201
+ ,positionMapping :: STM. Map NormalizedUri (Map TextDocumentVersion (PositionDelta , PositionMapping ))
202
202
-- ^ Map from a text document version to a PositionMapping that describes how to map
203
203
-- positions in a version of that document to positions in the latest version
204
204
-- First mapping is delta from previous version and second one is an
@@ -323,7 +323,6 @@ getIdeOptionsIO ide = do
323
323
-- for the version of that value.
324
324
lastValueIO :: IdeRule k v => ShakeExtras -> k -> NormalizedFilePath -> IO (Maybe (v , PositionMapping ))
325
325
lastValueIO s@ ShakeExtras {positionMapping,persistentKeys,state} k file = do
326
- allMappings <- readVar positionMapping
327
326
328
327
let readPersistent
329
328
| IdeTesting testing <- ideTesting s -- Don't read stale persistent values in tests
@@ -341,7 +340,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
341
340
return Nothing
342
341
Just (v,del,ver) -> do
343
342
void $ atomically $ STM. focus (Focus. alter (alterValue $ Stale (Just del) ver (toDyn v))) (toKey k file) state
344
- return $ Just (v,addDelta del $ mappingForVersion allMappings file ver)
343
+ atomically $ Just . (v,) . addDelta del <$> mappingForVersion positionMapping file ver
345
344
346
345
-- We got a new stale value from the persistent rule, insert it in the map without affecting diagnostics
347
346
alterValue new Nothing = Just (ValueWithDiagnostics new mempty ) -- If it wasn't in the map, give it empty diagnostics
@@ -354,8 +353,10 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
354
353
atomically (STM. lookup (toKey k file) state) >>= \ case
355
354
Nothing -> readPersistent
356
355
Just (ValueWithDiagnostics v _) -> case v of
357
- Succeeded ver (fromDynamic -> Just v) -> pure (Just (v, mappingForVersion allMappings file ver))
358
- Stale del ver (fromDynamic -> Just v) -> pure (Just (v, maybe id addDelta del $ mappingForVersion allMappings file ver))
356
+ Succeeded ver (fromDynamic -> Just v) ->
357
+ atomically $ Just . (v,) <$> mappingForVersion positionMapping file ver
358
+ Stale del ver (fromDynamic -> Just v) ->
359
+ atomically $ Just . (v,) . maybe id addDelta del <$> mappingForVersion positionMapping file ver
359
360
Failed p | not p -> readPersistent
360
361
_ -> pure Nothing
361
362
@@ -367,14 +368,13 @@ lastValue key file = do
367
368
liftIO $ lastValueIO s key file
368
369
369
370
mappingForVersion
370
- :: HMap. HashMap NormalizedUri (Map TextDocumentVersion (a , PositionMapping ))
371
+ :: STM. Map NormalizedUri (Map TextDocumentVersion (a , PositionMapping ))
371
372
-> NormalizedFilePath
372
373
-> TextDocumentVersion
373
- -> PositionMapping
374
- mappingForVersion allMappings file ver =
375
- maybe zeroMapping snd $
376
- Map. lookup ver =<<
377
- HMap. lookup (filePathToUri' file) allMappings
374
+ -> STM PositionMapping
375
+ mappingForVersion allMappings file ver = do
376
+ mapping <- STM. lookup (filePathToUri' file) allMappings
377
+ return $ maybe zeroMapping snd $ Map. lookup ver =<< mapping
378
378
379
379
type IdeRule k v =
380
380
( Shake. RuleResult k ~ v
@@ -506,7 +506,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
506
506
diagnostics <- STM. newIO
507
507
hiddenDiagnostics <- STM. newIO
508
508
publishedDiagnostics <- STM. newIO
509
- positionMapping <- newVar HMap. empty
509
+ positionMapping <- STM. newIO
510
510
knownTargetsVar <- newVar $ hashed HMap. empty
511
511
let restartShakeSession = shakeRestart ideState
512
512
persistentKeys <- newVar HMap. empty
@@ -1216,17 +1216,16 @@ getAllDiagnostics =
1216
1216
fmap (concatMap (\ (k,v) -> map (fromUri k,ShowDiag ,) $ getDiagnosticsFromStore v)) . ListT. toList . STM. listT
1217
1217
1218
1218
updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> List TextDocumentContentChangeEvent -> IO ()
1219
- updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} VersionedTextDocumentIdentifier {.. } (List changes) = do
1220
- modifyVar_ positionMapping $ \ allMappings -> do
1221
- let uri = toNormalizedUri _uri
1222
- let mappingForUri = HMap. lookupDefault Map. empty uri allMappings
1223
- let (_, updatedMapping) =
1219
+ updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} VersionedTextDocumentIdentifier {.. } (List changes) =
1220
+ atomically $ STM. focus (Focus. alter f) uri positionMapping
1221
+ where
1222
+ uri = toNormalizedUri _uri
1223
+ f = Just . f' . fromMaybe mempty
1224
+ f' mappingForUri = snd $
1224
1225
-- Very important to use mapAccum here so that the tails of
1225
1226
-- each mapping can be shared, otherwise quadratic space is
1226
1227
-- used which is evident in long running sessions.
1227
1228
Map. mapAccumRWithKey (\ acc _k (delta, _) -> let new = addDelta delta acc in (new, (delta, acc)))
1228
1229
zeroMapping
1229
1230
(Map. insert _version (shared_change, zeroMapping) mappingForUri)
1230
- pure $ HMap. insert uri updatedMapping allMappings
1231
- where
1232
- shared_change = mkDelta changes
1231
+ shared_change = mkDelta changes
0 commit comments