@@ -28,6 +28,7 @@ module Development.IDE.Core.Rules(
28
28
getDependencies ,
29
29
getParsedModule ,
30
30
getClientConfigAction ,
31
+ getParsedModuleWithComments
31
32
) where
32
33
33
34
import Fingerprint
@@ -242,9 +243,14 @@ getPackageHieFile ide mod file = do
242
243
_ -> MaybeT $ return Nothing
243
244
_ -> MaybeT $ return Nothing
244
245
245
- -- | Parse the contents of a daml file.
246
+ -- | Parse the contents of a haskell file.
246
247
getParsedModule :: NormalizedFilePath -> Action (Maybe ParsedModule )
247
- getParsedModule file = use GetParsedModule file
248
+ getParsedModule = use GetParsedModule
249
+
250
+ -- | Parse the contents of a haskell file,
251
+ -- ensuring comments are preserved in annotations
252
+ getParsedModuleWithComments :: NormalizedFilePath -> Action (Maybe ParsedModule )
253
+ getParsedModuleWithComments = use GetParsedModule
248
254
249
255
------------------------------------------------------------
250
256
-- Rules
@@ -307,8 +313,10 @@ getParsedModuleRule = defineEarlyCutoff $ \GetParsedModule file -> do
307
313
pure res
308
314
309
315
withOptHaddock :: ModSummary -> ModSummary
310
- withOptHaddock ms = ms{ms_hspp_opts = gopt_set (ms_hspp_opts ms) Opt_Haddock }
316
+ withOptHaddock = withOption Opt_Haddock
311
317
318
+ withOption :: GeneralFlag -> ModSummary -> ModSummary
319
+ withOption opt ms = ms{ms_hspp_opts= gopt_set (ms_hspp_opts ms) opt}
312
320
313
321
-- | Given some normal parse errors (first) and some from Haddock (second), merge them.
314
322
-- Ignore Haddock errors that are in both. Demote Haddock-only errors to warnings.
@@ -322,6 +330,16 @@ mergeParseErrorsHaddock normal haddock = normal ++
322
330
fixMessage x | " parse error " `T.isPrefixOf` x = " Haddock " <> x
323
331
| otherwise = " Haddock: " <> x
324
332
333
+ getParsedModuleWithCommentsRule :: Rules ()
334
+ getParsedModuleWithCommentsRule = defineEarlyCutoff $ \ GetParsedModuleWithComments file -> do
335
+ (ms, _) <- use_ GetModSummary file
336
+ sess <- use_ GhcSession file
337
+ opt <- getIdeOptions
338
+
339
+ let ms' = withOption Opt_KeepRawTokenStream ms
340
+
341
+ liftIO $ getParsedModuleDefinition (hscEnv sess) opt file ms'
342
+
325
343
getParsedModuleDefinition :: HscEnv -> IdeOptions -> NormalizedFilePath -> ModSummary -> IO (Maybe ByteString , ([FileDiagnostic ], Maybe ParsedModule ))
326
344
getParsedModuleDefinition packageState opt file ms = do
327
345
let fp = fromNormalizedFilePath file
@@ -948,6 +966,7 @@ mainRule = do
948
966
linkables <- liftIO $ newVar emptyModuleEnv
949
967
addIdeGlobal $ CompiledLinkables linkables
950
968
getParsedModuleRule
969
+ getParsedModuleWithCommentsRule
951
970
getLocatedImportsRule
952
971
getDependencyInformationRule
953
972
reportImportCyclesRule
0 commit comments