@@ -8,6 +8,7 @@ module Development.IDE.Core.Preprocessor
8
8
9
9
import Development.IDE.GHC.Compat
10
10
import qualified Development.IDE.GHC.Compat.Util as Util
11
+ import qualified Development.IDE.GHC.Util as Util
11
12
import Development.IDE.GHC.CPP
12
13
import Development.IDE.GHC.Orphans ()
13
14
@@ -36,7 +37,7 @@ import GHC.Utils.Outputable (renderWithContext)
36
37
37
38
-- | Given a file and some contents, apply any necessary preprocessors,
38
39
-- 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 )
40
41
preprocessor env filename mbContents = do
41
42
-- Perform unlit
42
43
(isOnDisk, contents) <-
@@ -48,6 +49,10 @@ preprocessor env filename mbContents = do
48
49
let isOnDisk = isNothing mbContents
49
50
return (isOnDisk, contents)
50
51
52
+ -- Compute the source hash before the preprocessor because this is
53
+ -- how GHC does it.
54
+ ! src_hash <- liftIO $ Util. fingerprintFromStringBuffer contents
55
+
51
56
-- Perform cpp
52
57
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
53
58
let dflags = hsc_dflags env
@@ -73,11 +78,11 @@ preprocessor env filename mbContents = do
73
78
74
79
-- Perform preprocessor
75
80
if not $ gopt Opt_Pp dflags then
76
- return (contents, opts, env)
81
+ return (contents, opts, env, src_hash )
77
82
else do
78
83
contents <- liftIO $ runPreprocessor env filename $ if isOnDisk then Nothing else Just contents
79
84
(opts, env) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
80
- return (contents, opts, env)
85
+ return (contents, opts, env, src_hash )
81
86
where
82
87
logAction :: IORef [CPPLog ] -> LogActionCompat
83
88
logAction cppLogs dflags _reason severity srcSpan _style msg = do
0 commit comments