@@ -135,6 +135,7 @@ import OpenTelemetry.Eventlog
135
135
import GHC.Fingerprint
136
136
137
137
import HieDb.Types
138
+ import Debug.Trace
138
139
139
140
-- | We need to serialize writes to the database, so we send any function that
140
141
-- needs to write to the database over the channel, where it will be picked up by
@@ -207,7 +208,7 @@ data ProgressEvent
207
208
= KickStarted
208
209
| KickCompleted
209
210
210
- type GetStalePersistent = NormalizedFilePath -> IdeAction (Maybe (Dynamic ,PositionMapping ))
211
+ type GetStalePersistent = NormalizedFilePath -> IdeAction (Maybe (Dynamic ,PositionDelta , TextDocumentVersion ))
211
212
212
213
getShakeExtras :: Action ShakeExtras
213
214
getShakeExtras = do
@@ -223,11 +224,11 @@ getShakeExtrasRules = do
223
224
-- This is called when we don't already have a result, or computing the rule failed.
224
225
-- The result of this function will always be marked as 'stale', and a 'proper' rebuild of the rule will
225
226
-- be queued if the rule hasn't run before.
226
- addPersistentRule :: IdeRule k v => k -> (NormalizedFilePath -> IdeAction (Maybe (v ,PositionMapping ))) -> Rules ()
227
+ addPersistentRule :: IdeRule k v => k -> (NormalizedFilePath -> IdeAction (Maybe (v ,PositionDelta , TextDocumentVersion ))) -> Rules ()
227
228
addPersistentRule k getVal = do
228
229
ShakeExtras {persistentKeys} <- getShakeExtrasRules
229
230
liftIO $ modifyVar_ persistentKeys $ \ hm -> do
230
- pure $ HMap. insert (Key k) (fmap (fmap (first toDyn)) . getVal) hm
231
+ pure $ HMap. insert (Key k) (fmap (fmap (first3 toDyn)) . getVal) hm
231
232
return ()
232
233
233
234
class Typeable a => IsIdeGlobal a where
@@ -291,34 +292,36 @@ getIdeOptionsIO ide = do
291
292
-- for the version of that value.
292
293
lastValueIO :: IdeRule k v => ShakeExtras -> k -> NormalizedFilePath -> IO (Maybe (v , PositionMapping ))
293
294
lastValueIO s@ ShakeExtras {positionMapping,persistentKeys,state} k file = do
295
+ hm <- readVar state
296
+ allMappings <- readVar positionMapping
297
+
294
298
let readPersistent = do
295
299
pmap <- readVar persistentKeys
296
300
mv <- runMaybeT $ do
297
301
liftIO $ Logger. logDebug (logger s) $ T. pack $ " LOOKUP UP PERSISTENT FOR" ++ show k
298
302
f <- MaybeT $ pure $ HMap. lookup (Key k) pmap
299
- (dv,mapping) <- MaybeT $ runIdeAction " lastValueIO" s $ f file
300
- MaybeT $ pure $ (,mapping) <$> fromDynamic dv
301
- modifyVar state $ \ hm -> case mv of
302
- Nothing -> pure (HMap. insertWith upd (file,Key k) (Failed True ) hm,Nothing )
303
- Just (v,mapping) -> pure (HMap. insertWith upd (file,Key k) (Stale Nothing (toDyn v)) hm, Just (v,mapping))
303
+ (dv,del,ver) <- MaybeT $ runIdeAction " lastValueIO" s $ f file
304
+ MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
305
+ modifyVar state $ \ hm -> pure $ case mv of
306
+ Nothing -> (HMap. insertWith upd (file,Key k) (Failed True ) hm,Nothing )
307
+ Just (v,del,ver) -> (HMap. insertWith upd (file,Key k) (Stale (Just del) ver (toDyn v)) hm
308
+ ,Just (v,addDelta del $ mappingForVersion allMappings file ver))
304
309
305
310
-- Update preserving 'monotonicity'
306
311
-- Don't want to overwrite a newer value with an older one
307
312
upd _new@ (Failed False ) old = old
308
313
upd new@ (Failed True ) (Failed False ) = new
309
314
upd _new@ (Failed True ) old = old
310
- upd new@ (Stale _ _) Failed {} = new
311
- upd new@ (Stale v _) old@ (Stale v' _) = if v >= v' then new else old
312
- upd new@ (Stale v _) old@ (Succeeded v' _) = if v >= v' then new else old
315
+ upd new@ (Stale _ _ _ ) Failed {} = new
316
+ upd new@ (Stale _ v _) old@ (Stale _ v' _) = if v >= v' then new else old
317
+ upd new@ (Stale _ v _) old@ (Succeeded v' _) = if v >= v' then new else old
313
318
upd new _old = new
314
319
315
- hm <- readVar state
316
- allMappings <- readVar positionMapping
317
320
case HMap. lookup (file,Key k) hm of
318
321
Nothing -> readPersistent
319
322
Just v -> case v of
320
323
Succeeded ver (fromDynamic -> Just v) -> pure (Just (v, mappingForVersion allMappings file ver))
321
- Stale ver (fromDynamic -> Just v) -> pure (Just (v, mappingForVersion allMappings file ver))
324
+ Stale del ver (fromDynamic -> Just v) -> pure (Just (v, maybe id addDelta del $ mappingForVersion allMappings file ver))
322
325
Failed p | not p -> readPersistent
323
326
_ -> pure Nothing
324
327
@@ -332,7 +335,7 @@ lastValue key file = do
332
335
valueVersion :: Value v -> Maybe TextDocumentVersion
333
336
valueVersion = \ case
334
337
Succeeded ver _ -> Just ver
335
- Stale ver _ -> Just ver
338
+ Stale _ ver _ -> Just ver
336
339
Failed _ -> Nothing
337
340
338
341
mappingForVersion
@@ -435,7 +438,7 @@ knownTargets = do
435
438
seqValue :: Value v -> b -> b
436
439
seqValue v b = case v of
437
440
Succeeded ver v -> rnf ver `seq` v `seq` b
438
- Stale ver v -> rnf ver `seq` v `seq` b
441
+ Stale d ver v -> rnf d `seq` rnf ver `seq` v `seq` b
439
442
Failed _ -> b
440
443
441
444
-- | Open a 'IdeState', should be shut using 'shakeShut'.
@@ -936,8 +939,8 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) (old
936
939
pure $ case staleV of
937
940
Nothing -> (toShakeValue ShakeResult bs, Failed False )
938
941
Just v -> case v of
939
- Succeeded ver v -> (toShakeValue ShakeStale bs, Stale ver v)
940
- Stale ver v -> (toShakeValue ShakeStale bs, Stale ver v)
942
+ Succeeded ver v -> (toShakeValue ShakeStale bs, Stale Nothing ver v)
943
+ Stale d ver v -> (toShakeValue ShakeStale bs, Stale d ver v)
941
944
Failed b -> (toShakeValue ShakeResult bs, Failed b)
942
945
Just v -> pure (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
943
946
liftIO $ setValues state key file res
@@ -1180,7 +1183,8 @@ filterVersionMap =
1180
1183
HMap. intersectionWith $ \ versionsToKeep versionMap -> Map. restrictKeys versionMap versionsToKeep
1181
1184
1182
1185
updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> List TextDocumentContentChangeEvent -> IO ()
1183
- updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} VersionedTextDocumentIdentifier {.. } (List changes) = do
1186
+ updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} v@ VersionedTextDocumentIdentifier {.. } (List changes) = do
1187
+ traceShowM (" UpdatePositionMapping" ,v,changes)
1184
1188
modifyVar_ positionMapping $ \ allMappings -> do
1185
1189
let uri = toNormalizedUri _uri
1186
1190
let mappingForUri = HMap. lookupDefault Map. empty uri allMappings
0 commit comments