@@ -93,7 +93,6 @@ import Data.List
93
93
import qualified Data.Set as Set
94
94
import qualified Data.Map as M
95
95
import qualified Data.Text as T
96
- import qualified Data.Text.IO as T
97
96
import qualified Data.Text.Encoding as T
98
97
import Development.IDE.GHC.Error
99
98
import Development.Shake hiding (Diagnostic )
@@ -119,6 +118,7 @@ import Control.Concurrent.Async (concurrently)
119
118
import Control.Monad.Reader
120
119
import Control.Exception.Safe
121
120
121
+ import Data.Coerce
122
122
import Control.Monad.State
123
123
import FastString (FastString (uniq ))
124
124
import qualified HeaderInfo as Hdr
@@ -572,15 +572,15 @@ persistentHieFileRule :: Rules ()
572
572
persistentHieFileRule = addPersistentRule GetHieAst $ \ file -> runMaybeT $ do
573
573
res <- readHieFileForSrcFromDisk file
574
574
vfs <- asks vfs
575
+ encoding <- liftIO getLocaleEncoding
575
576
(currentSource,ver) <- liftIO $ do
576
577
mvf <- getVirtualFile vfs $ filePathToUri' file
577
578
case mvf of
578
- Nothing -> (,Nothing ) <$> T. readFile (fromNormalizedFilePath file)
579
- Just vf -> pure $ (Rope. toText $ _text vf, Just $ _lsp_version vf)
580
- encoding <- liftIO $ getLocaleEncoding
579
+ Nothing -> (,Nothing ) . T. decode encoding <$> BS. readFile (fromNormalizedFilePath file)
580
+ Just vf -> pure (Rope. toText $ _text vf, Just $ _lsp_version vf)
581
581
let refmap = generateReferencesMap . getAsts . hie_asts $ res
582
582
del = deltaFromDiff (T. decode encoding $ hie_hs_src res) currentSource
583
- pure $ (HAR (hie_module res) (hie_asts res) refmap mempty (HieFromDisk res),del,ver)
583
+ pure (HAR (hie_module res) (hie_asts res) refmap mempty (HieFromDisk res),del,ver)
584
584
585
585
getHieAstRuleDefinition :: NormalizedFilePath -> HscEnv -> TcModuleResult -> Action (IdeResult HieAstResult )
586
586
getHieAstRuleDefinition f hsc tmr = do
@@ -590,8 +590,9 @@ getHieAstRuleDefinition f hsc tmr = do
590
590
isFoi <- use_ IsFileOfInterest f
591
591
diagsWrite <- case isFoi of
592
592
IsFOI Modified -> do
593
- liftIO $ eventer se $ LSP. NotCustomServer $
594
- LSP. NotificationMessage " 2.0" (LSP. CustomServerMethod " ghcide/reference/ready" ) (toJSON $ fromNormalizedFilePath f)
593
+ when (coerce $ ideTesting se) $
594
+ liftIO $ eventer se $ LSP. NotCustomServer $
595
+ LSP. NotificationMessage " 2.0" (LSP. CustomServerMethod " ghcide/reference/ready" ) (toJSON $ fromNormalizedFilePath f)
595
596
pure []
596
597
_ | Just asts <- masts -> do
597
598
source <- getSourceFileSource f
@@ -817,33 +818,34 @@ getModIfaceFromDiskRule = defineEarlyCutoff $ \GetModIfaceFromDisk f -> do
817
818
let fp = hiFileFingerPrint <$> res
818
819
return (fp, (diags' <> diags_session, res))
819
820
820
- case exists of
821
- -- Don't have a .hie file, must regenerate
822
- False -> regenerateHieFile
821
+ if exists
822
+ then do
823
823
-- Have a hie file, must check if it matches version in db
824
- True -> do
825
- hash <- liftIO $ getFileHash hie_loc
826
- mrow <- liftIO $ HieDb. lookupHieFileFromSource hiedb (fromNormalizedFilePath f)
827
- case mrow of
828
- -- All good, the db has indexed the file
829
- Just row
830
- | hash == HieDb. modInfoHash ( HieDb. hieModInfo row)
831
- , hie_loc == HieDb. hieModuleHieFile row -> do
824
+ hash <- liftIO $ getFileHash hie_loc
825
+ mrow <- liftIO $ HieDb. lookupHieFileFromSource hiedb (fromNormalizedFilePath f)
826
+ case mrow of
827
+ -- All good, the db has indexed the file
828
+ Just row
829
+ | hash == HieDb. modInfoHash ( HieDb. hieModInfo row)
830
+ , hie_loc == HieDb. hieModuleHieFile row -> do
831
+ when (coerce $ ideTesting se) $
832
832
liftIO $ eventer se $ LSP. NotCustomServer $
833
833
LSP. NotificationMessage " 2.0" (LSP. CustomServerMethod " ghcide/reference/ready" ) (toJSON $ fromNormalizedFilePath f)
834
- return (fp, (diags <> diags_session, Just x))
835
- -- Not in db, must re-index
836
- _ -> do
837
- mhf <- liftIO $ runIdeAction " GetModIfaceFromDisk" se $ runMaybeT $
838
- readHieFileFromDisk hie_loc
839
- case mhf of
840
- -- Uh oh, we failed to read the file for some reason, need to regenerate it
841
- Nothing -> regenerateHieFile
842
- -- can just re-index the file we read from disk
843
- Just hf -> liftIO $ do
844
- L. logInfo (logger se) $ " Re-indexing hie file for" <> T. pack (show (f,hash,fmap (HieDb. modInfoHash . HieDb. hieModInfo) mrow))
845
- indexHieFile se ms f hash hf
846
- return (fp, (diags <> diags_session, Just x))
834
+ return (fp, (diags <> diags_session, Just x))
835
+ -- Not in db, must re-index
836
+ _ -> do
837
+ mhf <- liftIO $ runIdeAction " GetModIfaceFromDisk" se $ runMaybeT $
838
+ readHieFileFromDisk hie_loc
839
+ case mhf of
840
+ -- Uh oh, we failed to read the file for some reason, need to regenerate it
841
+ Nothing -> regenerateHieFile
842
+ -- can just re-index the file we read from disk
843
+ Just hf -> liftIO $ do
844
+ L. logInfo (logger se) $ " Re-indexing hie file for" <> T. pack (show (f,hash,fmap (HieDb. modInfoHash . HieDb. hieModInfo) mrow))
845
+ indexHieFile se ms f hash hf
846
+ return (fp, (diags <> diags_session, Just x))
847
+ -- Don't have a .hie file, must regenerate
848
+ else regenerateHieFile
847
849
848
850
isHiFileStableRule :: Rules ()
849
851
isHiFileStableRule = defineEarlyCutoff $ \ IsHiFileStable f -> do
0 commit comments