@@ -21,6 +21,7 @@ module Development.IDE.Core.Compile
21
21
, generateByteCode
22
22
, generateHieAsts
23
23
, writeAndIndexHieFile
24
+ , HieDbModuleQuery (.. )
24
25
, indexHieFile
25
26
, writeHiFile
26
27
, getModSummaryFromImports
@@ -859,6 +860,10 @@ spliceExpressions Splices{..} =
859
860
, DL. fromList $ map fst awSplices
860
861
]
861
862
863
+ data HieDbModuleQuery
864
+ = HieDbModuleQuery ModuleName Unit
865
+ | DontCheckForModule
866
+
862
867
-- | In addition to indexing the `.hie` file, this function is responsible for
863
868
-- maintaining the 'IndexQueue' state and notifying the user about indexing
864
869
-- progress.
@@ -887,16 +892,14 @@ spliceExpressions Splices{..} =
887
892
-- TVar to 0 in order to set it up for a fresh indexing session. Otherwise, we
888
893
-- can just increment the 'indexCompleted' TVar and exit.
889
894
--
890
- indexHieFile :: ShakeExtras -> NormalizedFilePath -> HieDb. SourceFile -> Util. Fingerprint -> Compat. HieFile -> IO ()
891
- indexHieFile se hiePath sourceFile ! hash hf = do
895
+ indexHieFile :: ShakeExtras -> HieDbModuleQuery -> NormalizedFilePath -> HieDb. SourceFile -> Util. Fingerprint -> Compat. HieFile -> IO ()
896
+ indexHieFile se query hiePath sourceFile ! hash hf = do
892
897
IdeOptions {optProgressStyle} <- getIdeOptionsIO se
893
898
atomically $ do
894
899
pending <- readTVar indexPending
895
900
case HashMap. lookup hiePath pending of
896
901
Just pendingHash | pendingHash == hash -> pure () -- An index is already scheduled
897
902
_ -> do
898
- -- hiedb doesn't use the Haskell src, so we clear it to avoid unnecessarily keeping it around
899
- let ! hf' = hf{hie_hs_src = mempty }
900
903
modifyTVar' indexPending $ HashMap. insert hiePath hash
901
904
writeTQueue indexQueue $ \ withHieDb -> do
902
905
-- We are now in the worker thread
@@ -911,8 +914,24 @@ indexHieFile se hiePath sourceFile !hash hf = do
911
914
-- Using bracket, so even if an exception happen during withHieDb call,
912
915
-- the `post` (which clean the progress indicator) will still be called.
913
916
bracket_ (pre optProgressStyle) post $
914
- withHieDb ( \ db -> HieDb. addRefsFromLoaded db (fromNormalizedFilePath hiePath) sourceFile hash hf')
917
+ withHieDb indexIfNotAlready
915
918
where
919
+ -- hiedb doesn't use the Haskell src, so we clear it to avoid unnecessarily keeping it around
920
+ hf' :: Compat. HieFile
921
+ ! hf' = hf{hie_hs_src = mempty }
922
+ indexIfNotAlready :: HieDb -> IO ()
923
+ indexIfNotAlready db = case query of
924
+ DontCheckForModule -> doIndexing
925
+ HieDbModuleQuery moduleName unit -> do
926
+ mRow <- HieDb. lookupHieFile db moduleName unit
927
+ case mRow of
928
+ Nothing -> doIndexing
929
+ Just _row -> return ()
930
+ where
931
+ doIndexing :: IO ()
932
+ doIndexing =
933
+ HieDb. addRefsFromLoaded db (fromNormalizedFilePath hiePath) sourceFile hash hf'
934
+
916
935
HieDbWriter {.. } = hiedbWriter se
917
936
918
937
-- Get a progress token to report progress and update it for the current file
@@ -1005,7 +1024,7 @@ writeAndIndexHieFile hscEnv se mod_summary srcPath exports ast source =
1005
1024
GHC. mkHieFile' mod_summary exports ast source
1006
1025
atomicFileWrite se targetPath $ flip GHC. writeHieFile hf
1007
1026
hash <- Util. getFileHash targetPath
1008
- indexHieFile se (toNormalizedFilePath' targetPath) (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf
1027
+ indexHieFile se DontCheckForModule (toNormalizedFilePath' targetPath) (HieDb. RealFile $ fromNormalizedFilePath srcPath) hash hf
1009
1028
where
1010
1029
dflags = hsc_dflags hscEnv
1011
1030
mod_location = ms_location mod_summary
0 commit comments