@@ -139,6 +139,7 @@ import GHC.Core.Lint.Interactive
139
139
#if MIN_VERSION_ghc(9,7,0)
140
140
import Data.Foldable (toList )
141
141
import GHC.Unit.Module.Warnings
142
+ import Control.Concurrent.Async (async , withAsync )
142
143
#else
143
144
import Development.IDE.Core.FileStore (shareFilePath )
144
145
#endif
@@ -923,17 +924,19 @@ indexHieFile se mod_summary srcPath !hash hf = do
923
924
-- If the hash in the pending list doesn't match the current hash, then skip
924
925
Just pendingHash -> pendingHash /= hash
925
926
unless newerScheduled $ do
926
- -- Using bracket, so even if an exception happen during withHieDb call,
927
- -- the `post` (which clean the progress indicator) will still be called.
928
- bracket_ (pre optProgressStyle) post $
929
- withHieDb (\ db -> HieDb. addRefsFromLoaded db targetPath (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf')
930
- where
927
+ -- Using `finally`, 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
+ withAsync (reportProgress indexDoneB optProgressStyle) $ \ preAsync ->
931
+ flip finally (signalBarrier indexDoneB () ) $
932
+ withHieDb (\ db -> HieDb. addRefsFromLoaded db targetPath (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf')
933
+ where
931
934
mod_location = ms_location mod_summary
932
935
targetPath = Compat. ml_hie_file mod_location
933
936
HieDbWriter {.. } = hiedbWriter se
934
937
935
938
-- Get a progress token to report progress and update it for the current file
936
- pre style = do
939
+ reportProgress indexDoneB style = do
937
940
tok <- modifyVar indexProgressToken $ fmap dupe . \ case
938
941
x@ (Just _) -> pure x
939
942
-- Create a token if we don't already have one
@@ -944,15 +947,16 @@ indexHieFile se mod_summary srcPath !hash hf = do
944
947
u <- LSP. ProgressToken . LSP. InR . T. pack . show . hashUnique <$> liftIO Unique. newUnique
945
948
b <- liftIO newBarrier
946
949
void $ LSP. sendRequest LSP. SMethod_WindowWorkDoneProgressCreate (LSP. WorkDoneProgressCreateParams u) $ liftIO . signalBarrier b
947
- ready <- liftIO $ waitBarrier b
948
- LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams u $
949
- toJSON $ LSP. WorkDoneProgressBegin
950
- { _kind = LSP. AString @ " begin"
951
- , _title = " Indexing"
952
- , _cancellable = Nothing
953
- , _message = Nothing
954
- , _percentage = Nothing
955
- }
950
+ liftIO $ async $ do
951
+ _ready <- waitBarrier b
952
+ LSP. runLspT env $ LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams u $
953
+ toJSON $ LSP. WorkDoneProgressBegin
954
+ { _kind = LSP. AString @ " begin"
955
+ , _title = " Indexing"
956
+ , _cancellable = Nothing
957
+ , _message = Nothing
958
+ , _percentage = Nothing
959
+ }
956
960
pure (Just u)
957
961
958
962
(! done, ! remaining) <- atomically $ do
@@ -964,7 +968,6 @@ indexHieFile se mod_summary srcPath !hash hf = do
964
968
progressFrac = fromIntegral done / fromIntegral (done + remaining)
965
969
progressPct :: LSP. UInt
966
970
progressPct = floor $ 100 * progressFrac
967
-
968
971
whenJust (lspEnv se) $ \ env -> whenJust tok $ \ token -> LSP. runLspT env $
969
972
LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams token $
970
973
toJSON $
@@ -988,9 +991,9 @@ indexHieFile se mod_summary srcPath !hash hf = do
988
991
, _message = Nothing
989
992
, _percentage = Nothing
990
993
}
994
+ -- Report the progress once we are done indexing this file
995
+ liftIO $ waitBarrier indexDoneB
991
996
992
- -- Report the progress once we are done indexing this file
993
- post = do
994
997
mdone <- atomically $ do
995
998
-- Remove current element from pending
996
999
pending <- stateTVar indexPending $
0 commit comments