@@ -924,18 +924,17 @@ indexHieFile se mod_summary srcPath !hash hf = do
924
924
-- If the hash in the pending list doesn't match the current hash, then skip
925
925
Just pendingHash -> pendingHash /= hash
926
926
unless newerScheduled $ do
927
- -- Using `bracket`, so even if an exception happen during withHieDb call,
928
- -- the the ending part of `reportProgress` (which clean the progress indicator) will still be called.
929
- indexDoneB <- liftIO newBarrier
930
- bracket_ (liftIO $ atomically $ writeTQueue indexProgressThread (reportProgress indexDoneB optProgressStyle)) (signalBarrier indexDoneB () ) $
927
+ -- Using bracket, so even if an exception happen during withHieDb call,
928
+ -- the `post` (which clean the progress indicator) will still be called.
929
+ bracket_ (pre optProgressStyle) post $
931
930
withHieDb (\ db -> HieDb. addRefsFromLoaded db targetPath (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf')
932
931
where
933
932
mod_location = ms_location mod_summary
934
933
targetPath = Compat. ml_hie_file mod_location
935
934
HieDbWriter {.. } = hiedbWriter se
936
935
937
936
-- Get a progress token to report progress and update it for the current file
938
- reportProgress indexDoneB style = do
937
+ pre style = atomically $ writeTQueue indexProgressThread $ do
939
938
tok <- modifyVar indexProgressToken $ fmap dupe . \ case
940
939
x@ (Just _) -> pure x
941
940
-- Create a token if we don't already have one
@@ -990,9 +989,8 @@ indexHieFile se mod_summary srcPath !hash hf = do
990
989
, _message = Nothing
991
990
, _percentage = Nothing
992
991
}
993
- -- Report the progress once we are done indexing this file
994
- liftIO $ waitBarrier indexDoneB
995
-
992
+ -- Report the progress once we are done indexing this file
993
+ post = do
996
994
mdone <- atomically $ do
997
995
-- Remove current element from pending
998
996
pending <- stateTVar indexPending $
@@ -1001,22 +999,25 @@ indexHieFile se mod_summary srcPath !hash hf = do
1001
999
-- If we are done, report and reset completed
1002
1000
whenMaybe (HashMap. null pending) $
1003
1001
swapTVar indexCompleted 0
1004
- whenJust (lspEnv se) $ \ env -> LSP. runLspT env $
1005
- when (coerce $ ideTesting se) $
1006
- LSP. sendNotification (LSP. SMethod_CustomMethod (Proxy @ " ghcide/reference/ready" )) $
1007
- toJSON $ fromNormalizedFilePath srcPath
1008
- whenJust mdone $ \ done ->
1009
- modifyVar_ indexProgressToken $ \ tok -> do
1010
- whenJust (lspEnv se) $ \ env -> LSP. runLspT env $
1011
- whenJust tok $ \ token ->
1012
- LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams token $
1013
- toJSON $
1014
- LSP. WorkDoneProgressEnd
1015
- { _kind = LSP. AString @ " end"
1016
- , _message = Just $ " Finished indexing " <> T. pack (show done) <> " files"
1017
- }
1018
- -- We are done with the current indexing cycle, so destroy the token
1019
- pure Nothing
1002
+
1003
+ atomically $ do
1004
+ writeTQueue indexProgressThread $ do
1005
+ whenJust (lspEnv se) $ \ env -> LSP. runLspT env $
1006
+ when (coerce $ ideTesting se) $
1007
+ LSP. sendNotification (LSP. SMethod_CustomMethod (Proxy @ " ghcide/reference/ready" )) $
1008
+ toJSON $ fromNormalizedFilePath srcPath
1009
+ whenJust mdone $ \ done ->
1010
+ modifyVar_ indexProgressToken $ \ tok -> do
1011
+ whenJust (lspEnv se) $ \ env -> LSP. runLspT env $
1012
+ whenJust tok $ \ token ->
1013
+ LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams token $
1014
+ toJSON $
1015
+ LSP. WorkDoneProgressEnd
1016
+ { _kind = LSP. AString @ " end"
1017
+ , _message = Just $ " Finished indexing " <> T. pack (show done) <> " files"
1018
+ }
1019
+ -- We are done with the current indexing cycle, so destroy the token
1020
+ pure Nothing
1020
1021
1021
1022
writeAndIndexHieFile :: HscEnv -> ShakeExtras -> ModSummary -> NormalizedFilePath -> [GHC. AvailInfo ] -> HieASTs Type -> BS. ByteString -> IO [FileDiagnostic ]
1022
1023
writeAndIndexHieFile hscEnv se mod_summary srcPath exports ast source =
0 commit comments