@@ -72,7 +72,7 @@ import Control.Monad.Trans.Maybe
72
72
import Data.Aeson (Result (Success ),
73
73
toJSON )
74
74
import Data.Binary hiding (get , put )
75
- import qualified Data.ByteString.Char8 as BS
75
+ import qualified Data.ByteString as BS
76
76
import Data.Foldable
77
77
import Data.IntMap.Strict (IntMap )
78
78
import qualified Data.IntMap.Strict as IntMap
@@ -150,6 +150,8 @@ import TcRnMonad (tcg_dependent_fil
150
150
import qualified Data.Aeson.Types as A
151
151
import qualified HieDb
152
152
import Ide.Plugin.Config
153
+ import qualified Data.ByteString.Lazy as LBS
154
+ import qualified Data.Binary as B
153
155
154
156
-- | This is useful for rules to convert rules that can only produce errors or
155
157
-- a result into the more general IdeResult type that supports producing
@@ -308,7 +310,9 @@ priorityFilesOfInterest = Priority (-2)
308
310
-- and https://github.com/mpickering/ghcide/pull/22#issuecomment-625070490
309
311
-- GHC wiki about: https://gitlab.haskell.org/ghc/ghc/-/wikis/api-annotations
310
312
getParsedModuleRule :: Rules ()
311
- getParsedModuleRule = defineEarlyCutoff $ Rule $ \ GetParsedModule file -> do
313
+ getParsedModuleRule =
314
+ -- this rule does not have early cutoff since all its dependencies already have it
315
+ define $ \ GetParsedModule file -> do
312
316
ModSummaryResult {msrModSummary = ms} <- use_ GetModSummary file
313
317
sess <- use_ GhcSession file
314
318
let hsc = hscEnv sess
@@ -318,7 +322,7 @@ getParsedModuleRule = defineEarlyCutoff $ Rule $ \GetParsedModule file -> do
318
322
mainParse = getParsedModuleDefinition hsc opt file ms
319
323
320
324
-- Parse again (if necessary) to capture Haddock parse errors
321
- res@ (_, (_, pmod) ) <- if gopt Opt_Haddock dflags
325
+ res@ (_,pmod) <- if gopt Opt_Haddock dflags
322
326
then
323
327
liftIO mainParse
324
328
else do
@@ -330,20 +334,20 @@ getParsedModuleRule = defineEarlyCutoff $ Rule $ \GetParsedModule file -> do
330
334
-- If we can parse Haddocks, might as well use them
331
335
--
332
336
-- HLINT INTEGRATION: might need to save the other parsed module too
333
- ((fp,( diags,res)),(fph,( diagsh,resh) )) <- liftIO $ concurrently mainParse haddockParse
337
+ ((diags,res),( diagsh,resh)) <- liftIO $ concurrently mainParse haddockParse
334
338
335
339
-- Merge haddock and regular diagnostics so we can always report haddock
336
340
-- parse errors
337
341
let diagsM = mergeParseErrorsHaddock diags diagsh
338
342
case resh of
339
343
Just _
340
344
| HaddockParse <- optHaddockParse opt
341
- -> pure (fph, ( diagsM, resh) )
345
+ -> pure (diagsM, resh)
342
346
-- If we fail to parse haddocks, report the haddock diagnostics as well and
343
347
-- return the non-haddock parse.
344
348
-- This seems to be the correct behaviour because the Haddock flag is added
345
349
-- by us and not the user, so our IDE shouldn't stop working because of it.
346
- _ -> pure (fp, ( diagsM, res) )
350
+ _ -> pure (diagsM, res)
347
351
-- Add dependencies on included files
348
352
_ <- uses GetModificationTime $ map toNormalizedFilePath' (maybe [] pm_extra_src_files pmod)
349
353
pure res
@@ -372,26 +376,30 @@ mergeParseErrorsHaddock normal haddock = normal ++
372
376
-- | This rule provides a ParsedModule preserving all annotations,
373
377
-- including keywords, punctuation and comments.
374
378
-- So it is suitable for use cases where you need a perfect edit.
375
- -- FIXME this rule should probably not produce diagnostics
376
379
getParsedModuleWithCommentsRule :: Rules ()
377
- getParsedModuleWithCommentsRule = defineEarlyCutoff $ Rule $ \ GetParsedModuleWithComments file -> do
380
+ getParsedModuleWithCommentsRule =
381
+ -- The parse diagnostics are owned by the GetParsedModule rule
382
+ -- For this reason, this rule does not produce any diagnostics
383
+ defineNoDiagnostics $ \ GetParsedModuleWithComments file -> do
378
384
ModSummaryResult {msrModSummary = ms} <- use_ GetModSummary file
379
385
sess <- use_ GhcSession file
380
386
opt <- getIdeOptions
381
387
382
388
let ms' = withoutOption Opt_Haddock $ withOption Opt_KeepRawTokenStream ms
383
389
384
- liftIO $ getParsedModuleDefinition (hscEnv sess) opt file ms'
390
+ liftIO $ snd <$> getParsedModuleDefinition (hscEnv sess) opt file ms'
385
391
386
- getParsedModuleDefinition :: HscEnv -> IdeOptions -> NormalizedFilePath -> ModSummary -> IO (Maybe BS. ByteString , ([FileDiagnostic ], Maybe ParsedModule ))
392
+ getParsedModuleDefinition
393
+ :: HscEnv
394
+ -> IdeOptions
395
+ -> NormalizedFilePath
396
+ -> ModSummary -> IO (([FileDiagnostic ], Maybe ParsedModule ))
387
397
getParsedModuleDefinition packageState opt file ms = do
388
398
let fp = fromNormalizedFilePath file
389
399
(diag, res) <- parseModule opt packageState fp ms
390
400
case res of
391
- Nothing -> pure (Nothing , (diag, Nothing ))
392
- Just modu -> do
393
- mbFingerprint <- traverse (fmap fingerprintToBS . fingerprintFromStringBuffer) (ms_hspp_buf ms)
394
- pure (mbFingerprint, (diag, Just modu))
401
+ Nothing -> pure (diag, Nothing )
402
+ Just modu -> pure (diag, Just modu)
395
403
396
404
getLocatedImportsRule :: Rules ()
397
405
getLocatedImportsRule =
@@ -686,7 +694,7 @@ knownFilesRule :: Rules ()
686
694
knownFilesRule = defineEarlyCutOffNoFile $ \ GetKnownTargets -> do
687
695
alwaysRerun
688
696
fs <- knownTargets
689
- pure (BS. pack ( show $ hash fs) , unhashed fs)
697
+ pure (LBS. toStrict $ B. encode $ hash fs, unhashed fs)
690
698
691
699
getModuleGraphRule :: Rules ()
692
700
getModuleGraphRule = defineNoFile $ \ GetModuleGraph -> do
@@ -737,8 +745,8 @@ loadGhcSession = do
737
745
opts <- getIdeOptions
738
746
res <- optGhcSession opts
739
747
740
- let fingerprint = hash (sessionVersion res)
741
- return (BS. pack ( show fingerprint) , res)
748
+ let fingerprint = LBS. toStrict $ B. encode $ hash (sessionVersion res)
749
+ return (fingerprint, res)
742
750
743
751
defineEarlyCutoff $ Rule $ \ GhcSession file -> do
744
752
IdeGhcSession {loadSessionFun} <- useNoFile_ GhcSessionIO
@@ -759,7 +767,7 @@ loadGhcSession = do
759
767
Just {} -> " "
760
768
-- Hash the HscEnvEq returned so cutoff if it didn't change
761
769
-- from last time
762
- Nothing -> BS. pack ( show (hash (snd val) ))
770
+ Nothing -> LBS. toStrict $ B. encode (hash (snd val))
763
771
return (Just cutoffHash, val)
764
772
765
773
define $ \ GhcSessionDeps file -> ghcSessionDepsDefinition file
@@ -815,7 +823,9 @@ getModIfaceFromDiskRule = defineEarlyCutoff $ Rule $ \GetModIfaceFromDisk f -> d
815
823
-- disk since we are careful to write out the `.hie` file before writing the
816
824
-- `.hi` file
817
825
getModIfaceFromDiskAndIndexRule :: Rules ()
818
- getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ RuleNoDiagnostics $ \ GetModIfaceFromDiskAndIndex f -> do
826
+ getModIfaceFromDiskAndIndexRule =
827
+ -- doesn't need early cutoff since all its dependencies already have it
828
+ defineNoDiagnostics $ \ GetModIfaceFromDiskAndIndex f -> do
819
829
x <- use_ GetModIfaceFromDisk f
820
830
se@ ShakeExtras {hiedb} <- getShakeExtras
821
831
@@ -844,8 +854,7 @@ getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ RuleNoDiagnostics $ \GetMo
844
854
L. logDebug (logger se) $ " Re-indexing hie file for" <> T. pack (fromNormalizedFilePath f)
845
855
indexHieFile se ms f hash hf
846
856
847
- let fp = hiFileFingerPrint x
848
- return (Just fp, Just x)
857
+ return (Just x)
849
858
850
859
isHiFileStableRule :: Rules ()
851
860
isHiFileStableRule = defineEarlyCutoff $ RuleNoDiagnostics $ \ IsHiFileStable f -> do
@@ -866,7 +875,11 @@ isHiFileStableRule = defineEarlyCutoff $ RuleNoDiagnostics $ \IsHiFileStable f -
866
875
pure $ if all (== SourceUnmodifiedAndStable ) deps
867
876
then SourceUnmodifiedAndStable
868
877
else SourceUnmodified
869
- return (Just (BS. pack $ show sourceModified), Just sourceModified)
878
+ return (Just (summarize sourceModified), Just sourceModified)
879
+ where
880
+ summarize SourceModified = BS. singleton 1
881
+ summarize SourceUnmodified = BS. singleton 2
882
+ summarize SourceUnmodifiedAndStable = BS. singleton 3
870
883
871
884
getModSummaryRule :: Rules ()
872
885
getModSummaryRule = do
@@ -942,7 +955,7 @@ getModIfaceWithoutLinkableRule = defineEarlyCutoff $ RuleNoDiagnostics $ \GetMod
942
955
mhfr <- use GetModIface f
943
956
let mhfr' = fmap (\ x -> x{ hirHomeMod = (hirHomeMod x){ hm_linkable = Just (error msg) } }) mhfr
944
957
msg = " tried to look at linkable for GetModIfaceWithoutLinkable for " ++ show f
945
- pure (fingerprintToBS . getModuleHash . hirModIface <$> mhfr', mhfr')
958
+ pure (hirIfaceFp <$> mhfr', mhfr')
946
959
947
960
-- | Also generates and indexes the `.hie` file, along with the `.o` file if needed
948
961
-- Invariant maintained is that if the `.hi` file was successfully written, then the
@@ -953,12 +966,12 @@ regenerateHiFile sess f ms compNeeded = do
953
966
opt <- getIdeOptions
954
967
955
968
-- Embed haddocks in the interface file
956
- (_, ( diags, mb_pm) ) <- liftIO $ getParsedModuleDefinition hsc opt f (withOptHaddock ms)
969
+ (diags, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f (withOptHaddock ms)
957
970
(diags, mb_pm) <- case mb_pm of
958
971
Just _ -> return (diags, mb_pm)
959
972
Nothing -> do
960
973
-- if parsing fails, try parsing again with Haddock turned off
961
- (_, ( diagsNoHaddock, mb_pm) ) <- liftIO $ getParsedModuleDefinition hsc opt f ms
974
+ (diagsNoHaddock, mb_pm) <- liftIO $ getParsedModuleDefinition hsc opt f ms
962
975
return (mergeParseErrorsHaddock diagsNoHaddock diags, mb_pm)
963
976
case mb_pm of
964
977
Nothing -> return (diags, Nothing )
@@ -1021,7 +1034,7 @@ getClientSettingsRule :: Rules ()
1021
1034
getClientSettingsRule = defineEarlyCutOffNoFile $ \ GetClientSettings -> do
1022
1035
alwaysRerun
1023
1036
settings <- clientSettings <$> getIdeConfiguration
1024
- return (BS. pack . show . hash $ settings, settings)
1037
+ return (LBS. toStrict $ B. encode $ hash settings, settings)
1025
1038
1026
1039
-- | Returns the client configurarion stored in the IdeState.
1027
1040
-- You can use this function to access it from shake Rules
@@ -1062,7 +1075,7 @@ needsCompilationRule = defineEarlyCutoff $ RuleNoDiagnostics $ \NeedsCompilation
1062
1075
(uses NeedsCompilation revdeps)
1063
1076
pure $ computeLinkableType ms modsums (map join needsComps)
1064
1077
1065
- pure (Just $ BS. pack $ show $ hash res, Just res)
1078
+ pure (Just $ LBS. toStrict $ B. encode $ hash res, Just res)
1066
1079
where
1067
1080
uses_th_qq (ms_hspp_opts -> dflags) =
1068
1081
xopt LangExt. TemplateHaskell dflags || xopt LangExt. QuasiQuotes dflags
0 commit comments