@@ -8,6 +8,7 @@ module Development.IDE.Core.Preprocessor
88
99import Development.IDE.GHC.Compat
1010import qualified Development.IDE.GHC.Compat.Util as Util
11+ import qualified Development.IDE.GHC.Util as Util
1112import Development.IDE.GHC.CPP
1213import Development.IDE.GHC.Orphans ()
1314
@@ -36,7 +37,7 @@ import GHC.Utils.Outputable (renderWithContext)
3637
3738-- | Given a file and some contents, apply any necessary preprocessors,
3839-- e.g. unlit/cpp. Return the resulting buffer and the DynFlags it implies.
39- preprocessor :: HscEnv -> FilePath -> Maybe Util. StringBuffer -> ExceptT [FileDiagnostic ] IO (Util. StringBuffer , [String ], HscEnv )
40+ preprocessor :: HscEnv -> FilePath -> Maybe Util. StringBuffer -> ExceptT [FileDiagnostic ] IO (Util. StringBuffer , [String ], HscEnv , Util. Fingerprint )
4041preprocessor env filename mbContents = do
4142 -- Perform unlit
4243 (isOnDisk, contents) <-
@@ -48,6 +49,10 @@ preprocessor env filename mbContents = do
4849 let isOnDisk = isNothing mbContents
4950 return (isOnDisk, contents)
5051
52+ -- Compute the source hash before the preprocessor because this is
53+ -- how GHC does it.
54+ ! src_hash <- liftIO $ Util. fingerprintFromStringBuffer contents
55+
5156 -- Perform cpp
5257 (opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
5358 let dflags = hsc_dflags env
@@ -73,11 +78,11 @@ preprocessor env filename mbContents = do
7378
7479 -- Perform preprocessor
7580 if not $ gopt Opt_Pp dflags then
76- return (contents, opts, env)
81+ return (contents, opts, env, src_hash )
7782 else do
7883 contents <- liftIO $ runPreprocessor env filename $ if isOnDisk then Nothing else Just contents
7984 (opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
80- return (contents, opts, env)
85+ return (contents, opts, env, src_hash )
8186 where
8287 logAction :: IORef [CPPLog ] -> LogActionCompat
8388 logAction cppLogs dflags _reason severity srcSpan _style msg = do
0 commit comments