@@ -28,6 +28,7 @@ module Development.IDE.Core.Rules(
2828 getDependencies ,
2929 getParsedModule ,
3030 getClientConfigAction ,
31+ getParsedModuleWithComments
3132 ) where
3233
3334import Fingerprint
@@ -242,9 +243,14 @@ getPackageHieFile ide mod file = do
242243 _ -> MaybeT $ return Nothing
243244 _ -> MaybeT $ return Nothing
244245
245- -- | Parse the contents of a daml file.
246+ -- | Parse the contents of a haskell file.
246247getParsedModule :: 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
248254
249255------------------------------------------------------------
250256-- Rules
@@ -307,8 +313,10 @@ getParsedModuleRule = defineEarlyCutoff $ \GetParsedModule file -> do
307313 pure res
308314
309315withOptHaddock :: ModSummary -> ModSummary
310- withOptHaddock ms = ms{ms_hspp_opts = gopt_set (ms_hspp_opts ms) Opt_Haddock }
316+ withOptHaddock = withOption Opt_Haddock
311317
318+ withOption :: GeneralFlag -> ModSummary -> ModSummary
319+ withOption opt ms = ms{ms_hspp_opts= gopt_set (ms_hspp_opts ms) opt}
312320
313321-- | Given some normal parse errors (first) and some from Haddock (second), merge them.
314322-- Ignore Haddock errors that are in both. Demote Haddock-only errors to warnings.
@@ -322,6 +330,16 @@ mergeParseErrorsHaddock normal haddock = normal ++
322330 fixMessage x | " parse error " `T.isPrefixOf` x = " Haddock " <> x
323331 | otherwise = " Haddock: " <> x
324332
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+
325343getParsedModuleDefinition :: HscEnv -> IdeOptions -> NormalizedFilePath -> ModSummary -> IO (Maybe ByteString , ([FileDiagnostic ], Maybe ParsedModule ))
326344getParsedModuleDefinition packageState opt file ms = do
327345 let fp = fromNormalizedFilePath file
@@ -948,6 +966,7 @@ mainRule = do
948966 linkables <- liftIO $ newVar emptyModuleEnv
949967 addIdeGlobal $ CompiledLinkables linkables
950968 getParsedModuleRule
969+ getParsedModuleWithCommentsRule
951970 getLocatedImportsRule
952971 getDependencyInformationRule
953972 reportImportCyclesRule
0 commit comments