@@ -18,7 +18,8 @@ module Development.IDE.Core.Compile
18
18
, addRelativeImport
19
19
, mkTcModuleResult
20
20
, generateByteCode
21
- , generateAndWriteHieFile
21
+ , generateHieAsts
22
+ , writeHieFile
22
23
, writeHiFile
23
24
, getModSummaryFromImports
24
25
, loadHieFile
@@ -55,7 +56,7 @@ import ErrUtils
55
56
#endif
56
57
57
58
import Finder
58
- import Development.IDE.GHC.Compat hiding (parseModule , typecheckModule )
59
+ import Development.IDE.GHC.Compat hiding (parseModule , typecheckModule , writeHieFile )
59
60
import qualified Development.IDE.GHC.Compat as GHC
60
61
import qualified Development.IDE.GHC.Compat as Compat
61
62
import GhcMonad
@@ -64,7 +65,7 @@ import qualified HeaderInfo as Hdr
64
65
import HscMain (hscInteractive , hscSimplify )
65
66
import MkIface
66
67
import StringBuffer as SB
67
- import TcRnMonad (tct_id , TcTyThing (AGlobal , ATcId ), initTc , initIfaceLoad , tcg_th_coreplugins )
68
+ import TcRnMonad (tct_id , TcTyThing (AGlobal , ATcId ), initTc , initIfaceLoad , tcg_th_coreplugins , tcg_binds )
68
69
import TcIface (typecheckIface )
69
70
import TidyPgm
70
71
@@ -270,7 +271,7 @@ mkTcModuleResult tcm upgradedError = do
270
271
(iface, _) <- liftIO $ mkIfaceTc session Nothing sf details tcGblEnv
271
272
#endif
272
273
let mod_info = HomeModInfo iface details Nothing
273
- return $ TcModuleResult tcm mod_info upgradedError
274
+ return $ TcModuleResult tcm mod_info upgradedError Nothing
274
275
where
275
276
(tcGblEnv, details) = tm_internals_ tcm
276
277
@@ -281,19 +282,25 @@ atomicFileWrite targetPath write = do
281
282
(tempFilePath, cleanUp) <- newTempFileWithin dir
282
283
(write tempFilePath >> renameFile tempFilePath targetPath) `onException` cleanUp
283
284
284
- generateAndWriteHieFile :: HscEnv -> TypecheckedModule -> BS. ByteString -> IO [FileDiagnostic ]
285
- generateAndWriteHieFile hscEnv tcm source =
286
- handleGenerationErrors dflags " extended interface generation" $ do
285
+ generateHieAsts :: HscEnv -> TypecheckedModule -> IO ( [FileDiagnostic ], Maybe ( HieASTs Type ))
286
+ generateHieAsts hscEnv tcm =
287
+ handleGenerationErrors' dflags " extended interface generation" $ do
287
288
case tm_renamed_source tcm of
288
- Just rnsrc -> do
289
- hf <- runHsc hscEnv $
290
- GHC. mkHieFile mod_summary (fst $ tm_internals_ tcm) rnsrc source
291
- atomicFileWrite targetPath $ flip GHC. writeHieFile hf
289
+ Just rnsrc -> runHsc hscEnv $
290
+ Just <$> GHC. enrichHie (tcg_binds $ fst $ tm_internals_ tcm) rnsrc
292
291
_ ->
293
- return ()
292
+ return Nothing
293
+ where
294
+ dflags = hsc_dflags hscEnv
295
+
296
+ writeHieFile :: HscEnv -> ModSummary -> [GHC. AvailInfo ] -> HieASTs Type -> BS. ByteString -> IO [FileDiagnostic ]
297
+ writeHieFile hscEnv mod_summary exports ast source =
298
+ handleGenerationErrors dflags " extended interface write/compression" $ do
299
+ hf <- runHsc hscEnv $
300
+ GHC. mkHieFile' mod_summary exports ast source
301
+ atomicFileWrite targetPath $ flip GHC. writeHieFile hf
294
302
where
295
303
dflags = hsc_dflags hscEnv
296
- mod_summary = pm_mod_summary $ tm_parsed_module tcm
297
304
mod_location = ms_location mod_summary
298
305
targetPath = Compat. ml_hie_file mod_location
299
306
@@ -315,6 +322,14 @@ handleGenerationErrors dflags source action =
315
322
. ((" Error during " ++ T. unpack source) ++ ) . show @ SomeException
316
323
]
317
324
325
+ handleGenerationErrors' :: DynFlags -> T. Text -> IO (Maybe a ) -> IO ([FileDiagnostic ], Maybe a )
326
+ handleGenerationErrors' dflags source action =
327
+ fmap ([] ,) action `catches`
328
+ [ Handler $ return . (,Nothing ) . diagFromGhcException source dflags
329
+ , Handler $ return . (,Nothing ) . diagFromString source DsError (noSpan " <internal>" )
330
+ . ((" Error during " ++ T. unpack source) ++ ) . show @ SomeException
331
+ ]
332
+
318
333
319
334
-- | Setup the environment that GHC needs according to our
320
335
-- best understanding (!)
0 commit comments