@@ -129,6 +129,7 @@ import GHC.Driver.Config.CoreToStg.Prep
129129#if MIN_VERSION_ghc(9,7,0)
130130import Data.Foldable (toList )
131131import GHC.Unit.Module.Warnings
132+ import Development.IDE.Core.ProgressReporting (progressReporting , ProgressReporting (.. ))
132133#else
133134import Development.IDE.Core.FileStore (shareFilePath )
134135#endif
@@ -898,6 +899,7 @@ indexHieFile se mod_summary srcPath !hash hf = do
898899 _ -> do
899900 -- hiedb doesn't use the Haskell src, so we clear it to avoid unnecessarily keeping it around
900901 let ! hf' = hf{hie_hs_src = mempty }
902+ -- todo, this is the real pending count
901903 modifyTVar' indexPending $ HashMap. insert srcPath hash
902904 writeTQueue indexQueue $ \ withHieDb -> do
903905 -- We are now in the worker thread
@@ -911,69 +913,20 @@ indexHieFile se mod_summary srcPath !hash hf = do
911913 unless newerScheduled $ do
912914 -- Using bracket, so even if an exception happen during withHieDb call,
913915 -- the `post` (which clean the progress indicator) will still be called.
914- bracket_ (pre optProgressStyle) post $
915- withHieDb (\ db -> HieDb. addRefsFromLoaded db targetPath (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf')
916+ tok <- modifyVar indexProgressToken $ fmap (first Just . dupe) . \ case
917+ Just x -> return x
918+ -- create a progressReport if we don't already have one
919+ Nothing -> do
920+ tt <- progressReporting (lspEnv se) " Indexing" optProgressStyle
921+ progressUpdate tt ProgressStarted
922+ return tt
923+ inProgress tok srcPath
924+ (withHieDb (\ db -> HieDb. addRefsFromLoaded db targetPath (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf'))
925+ `finally` post
916926 where
917927 mod_location = ms_location mod_summary
918928 targetPath = Compat. ml_hie_file mod_location
919929 HieDbWriter {.. } = hiedbWriter se
920-
921- -- Get a progress token to report progress and update it for the current file
922- pre style = do
923- tok <- modifyVar indexProgressToken $ fmap dupe . \ case
924- x@ (Just _) -> pure x
925- -- Create a token if we don't already have one
926- Nothing -> do
927- case lspEnv se of
928- Nothing -> pure Nothing
929- Just env -> LSP. runLspT env $ do
930- u <- LSP. ProgressToken . LSP. InR . T. pack . show . hashUnique <$> liftIO Unique. newUnique
931- -- TODO: Wait for the progress create response to use the token
932- _ <- LSP. sendRequest LSP. SMethod_WindowWorkDoneProgressCreate (LSP. WorkDoneProgressCreateParams u) (const $ pure () )
933- LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams u $
934- toJSON $ LSP. WorkDoneProgressBegin
935- { _kind = LSP. AString @ " begin"
936- , _title = " Indexing"
937- , _cancellable = Nothing
938- , _message = Nothing
939- , _percentage = Nothing
940- }
941- pure (Just u)
942-
943- (! done, ! remaining) <- atomically $ do
944- done <- readTVar indexCompleted
945- remaining <- HashMap. size <$> readTVar indexPending
946- pure (done, remaining)
947- let
948- progressFrac :: Double
949- progressFrac = fromIntegral done / fromIntegral (done + remaining)
950- progressPct :: LSP. UInt
951- progressPct = floor $ 100 * progressFrac
952-
953- whenJust (lspEnv se) $ \ env -> whenJust tok $ \ token -> LSP. runLspT env $
954- LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams token $
955- toJSON $
956- case style of
957- Percentage -> LSP. WorkDoneProgressReport
958- { _kind = LSP. AString @ " report"
959- , _cancellable = Nothing
960- , _message = Nothing
961- , _percentage = Just progressPct
962- }
963- Explicit -> LSP. WorkDoneProgressReport
964- { _kind = LSP. AString @ " report"
965- , _cancellable = Nothing
966- , _message = Just $
967- T. pack " (" <> T. pack (show done) <> " /" <> T. pack (show $ done + remaining) <> " )..."
968- , _percentage = Nothing
969- }
970- NoProgress -> LSP. WorkDoneProgressReport
971- { _kind = LSP. AString @ " report"
972- , _cancellable = Nothing
973- , _message = Nothing
974- , _percentage = Nothing
975- }
976-
977930 -- Report the progress once we are done indexing this file
978931 post = do
979932 mdone <- atomically $ do
@@ -988,16 +941,11 @@ indexHieFile se mod_summary srcPath !hash hf = do
988941 when (coerce $ ideTesting se) $
989942 LSP. sendNotification (LSP. SMethod_CustomMethod (Proxy @ " ghcide/reference/ready" )) $
990943 toJSON $ fromNormalizedFilePath srcPath
991- whenJust mdone $ \ done ->
944+ whenJust mdone $ \ _ ->
992945 modifyVar_ indexProgressToken $ \ tok -> do
993- whenJust (lspEnv se) $ \ env -> LSP. runLspT env $
994- whenJust tok $ \ token ->
995- LSP. sendNotification LSP. SMethod_Progress $ LSP. ProgressParams token $
996- toJSON $
997- LSP. WorkDoneProgressEnd
998- { _kind = LSP. AString @ " end"
999- , _message = Just $ " Finished indexing " <> T. pack (show done) <> " files"
1000- }
946+ case tok of
947+ Just token -> progressUpdate token ProgressCompleted
948+ Nothing -> return ()
1001949 -- We are done with the current indexing cycle, so destroy the token
1002950 pure Nothing
1003951
0 commit comments