@@ -28,6 +28,8 @@ module Development.IDE.Core.Compile
28
28
, loadInterface
29
29
, loadModulesHome
30
30
, setupFinderCache
31
+ , getDocsNonInteractive
32
+ , getDocsNonInteractive'
31
33
, getDocsBatch
32
34
, lookupName
33
35
,mergeEnvs ) where
@@ -986,12 +988,20 @@ mkDetailsFromIface session iface linkable = do
986
988
initIfaceLoad hsc' (typecheckIface iface)
987
989
return (HomeModInfo iface details linkable)
988
990
991
+ fakeSpan :: RealSrcSpan
992
+ fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util. fsLit " <ghcide>" ) 1 1
989
993
990
- -- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
991
- -- The interactive paths create problems in ghc-lib builds
992
- --- and lead to fun errors like "Cannot continue after interface file error".
993
- getDocsNonInteractive :: Name -> IOEnv (Env TcGblEnv TcLclEnv ) (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
994
- getDocsNonInteractive name = do
994
+ initTypecheckEnv :: HscEnv -> Module -> TcRn r -> IO (Messages , Maybe r )
995
+ initTypecheckEnv hsc_env mod = initTc hsc_env HsSrcFile False mod fakeSpan
996
+
997
+ getDocsNonInteractive'
998
+ :: Name
999
+ -> IOEnv
1000
+ (Env TcGblEnv TcLclEnv )
1001
+ (Name ,
1002
+ Either
1003
+ GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
1004
+ getDocsNonInteractive' name =
995
1005
case nameModule_maybe name of
996
1006
Nothing -> return (name, Left $ NameHasNoModule name)
997
1007
Just mod -> do
@@ -1003,7 +1013,7 @@ getDocsNonInteractive name = do
1003
1013
<- loadModuleInterface " getModuleInterface" mod
1004
1014
let
1005
1015
isNameCompiled =
1006
- -- TODO : Find a more direct indicator.
1016
+ -- comment from GHC : Find a more direct indicator.
1007
1017
case nameSrcLoc name of
1008
1018
RealSrcLoc {} -> False
1009
1019
UnhelpfulLoc {} -> True
@@ -1012,6 +1022,15 @@ getDocsNonInteractive name = do
1012
1022
then Left $ NoDocsInIface mod isNameCompiled
1013
1023
else Right (Map. lookup name dmap, Map. lookup name amap)
1014
1024
1025
+ -- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
1026
+ -- The interactive paths create problems in ghc-lib builds
1027
+ --- and lead to fun errors like "Cannot continue after interface file error".
1028
+ getDocsNonInteractive :: HscEnv -> Module -> Name -> IO (Either ErrorMessages (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString ))))
1029
+ getDocsNonInteractive hsc_env mod name = do
1030
+ ((_warns,errs), res) <- initTypecheckEnv hsc_env mod $ getDocsNonInteractive' name
1031
+ pure $ maybeToEither errs res
1032
+
1033
+
1015
1034
-- | Non-interactive, batch version of 'GHC.Runtime.Eval.getDocs'.
1016
1035
getDocsBatch
1017
1036
:: HscEnv
@@ -1020,13 +1039,10 @@ getDocsBatch
1020
1039
-- 2021-11-18: NOTE: Map Int would become IntMap if next GHCs.
1021
1040
-> IO (Either ErrorMessages (Map. Map Name (Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))))
1022
1041
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
1023
- getDocsBatch hsc_env _mod _names = do
1024
- ((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map. fromList <$> traverse getDocsNonInteractive _names
1042
+ getDocsBatch hsc_env mod names = do
1043
+ ((_warns,errs), res) <- initTypecheckEnv hsc_env mod $ Map. fromList <$> traverse getDocsNonInteractive' names
1025
1044
pure $ maybeToEither errs res
1026
1045
1027
- fakeSpan :: RealSrcSpan
1028
- fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util. fsLit " <ghcide>" ) 1 1
1029
-
1030
1046
-- | Non-interactive, batch version of 'InteractiveEval.lookupNames'.
1031
1047
-- The interactive paths create problems in ghc-lib builds
1032
1048
--- and leads to fun errors like "Cannot continue after interface file error".
@@ -1035,7 +1051,7 @@ lookupName :: HscEnv
1035
1051
-> Name
1036
1052
-> IO (Maybe TyThing )
1037
1053
lookupName hsc_env mod name = do
1038
- (_messages, res) <- initTc hsc_env HsSrcFile False mod fakeSpan $ do
1054
+ (_messages, res) <- initTypecheckEnv hsc_env mod $ do
1039
1055
tcthing <- tcLookup name
1040
1056
case tcthing of
1041
1057
AGlobal thing -> return thing
0 commit comments