Skip to content

Commit 8710341

Browse files
committed
spawn a progress thread for indexHieFile
1 parent bae3f0d commit 8710341

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ runWithDb recorder fp k = do
403403
withAsync (writerThread withWriteDbRetryable chan) $ \_ -> do
404404
withHieDb fp (\readDb -> k (makeWithHieDbRetryable recorder rng readDb) chan)
405405
where
406+
progressThread :: TQueue (IO ()) -> IO ()
407+
progressThread chan = forever $ join $ atomically $ readTQueue chan
408+
406409
writerThread :: WithHieDb -> IndexQueue -> IO ()
407410
writerThread withHieDbRetryable chan = do
408411
-- Clear the index of any files that might have been deleted since the last run

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ indexHieFile se mod_summary srcPath !hash hf = do
927927
-- Using `bracket`, so even if an exception happen during withHieDb call,
928928
-- the the ending part of `reportProgress` (which clean the progress indicator) will still be called.
929929
indexDoneB <- liftIO newBarrier
930-
bracket_ (liftIO $ async (reportProgress indexDoneB optProgressStyle)) (signalBarrier indexDoneB ()) $
930+
bracket_ (liftIO $ atomically $ writeTQueue indexProgressThread (reportProgress indexDoneB optProgressStyle)) (signalBarrier indexDoneB ()) $
931931
withHieDb (\db -> HieDb.addRefsFromLoaded db targetPath (HieDb.RealFile $ fromNormalizedFilePath srcPath) hash hf')
932932
where
933933
mod_location = ms_location mod_summary

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ instance Pretty Log where
245245
-- a worker thread.
246246
data HieDbWriter
247247
= HieDbWriter
248-
{ indexQueue :: IndexQueue
249-
, indexPending :: TVar (HMap.HashMap NormalizedFilePath Fingerprint) -- ^ Avoid unnecessary/out of date indexing
250-
, indexCompleted :: TVar Int -- ^ to report progress
251-
, indexProgressToken :: Var (Maybe LSP.ProgressToken)
248+
{ indexQueue :: IndexQueue
249+
, indexPending :: TVar (HMap.HashMap NormalizedFilePath Fingerprint) -- ^ Avoid unnecessary/out of date indexing
250+
, indexCompleted :: TVar Int -- ^ to report progress
251+
, indexProgressToken :: Var (Maybe LSP.ProgressToken)
252+
, indexProgressThread :: TQueue (IO ())
252253
-- ^ This is a Var instead of a TVar since we need to do IO to initialise/update, so we need a lock
253254
}
254255

@@ -653,6 +654,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins debouncer
653654
indexCompleted <- newTVarIO 0
654655
semanticTokensId <- newTVarIO 0
655656
indexProgressToken <- newVar Nothing
657+
indexProgressThread <- newTQueueIO
656658
let hiedbWriter = HieDbWriter{..}
657659
exportsMap <- newTVarIO mempty
658660
-- lazily initialize the exports map with the contents of the hiedb

0 commit comments

Comments
 (0)