@@ -27,6 +27,7 @@ module Development.IDE.Core.Compile
27
27
, loadHieFile
28
28
, loadInterface
29
29
, loadModulesHome
30
+ , getDocsNonInteractive
30
31
, getDocsBatch
31
32
, lookupName
32
33
,mergeEnvs ) where
@@ -1016,12 +1017,20 @@ mkDetailsFromIface session iface linkable = do
1016
1017
initIfaceLoad hsc' (typecheckIface iface)
1017
1018
return (HomeModInfo iface details linkable)
1018
1019
1020
+ fakeSpan :: RealSrcSpan
1021
+ fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util. fsLit " <ghcide>" ) 1 1
1019
1022
1020
- -- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
1021
- -- The interactive paths create problems in ghc-lib builds
1022
- --- and lead to fun errors like "Cannot continue after interface file error".
1023
- getDocsNonInteractive :: Name -> IOEnv (Env TcGblEnv TcLclEnv ) (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
1024
- getDocsNonInteractive name = do
1023
+ initTypecheckEnv :: HscEnv -> Module -> TcRn r -> IO (Messages , Maybe r )
1024
+ initTypecheckEnv hsc_env mod = initTc hsc_env HsSrcFile False mod fakeSpan
1025
+
1026
+ getDocsNonInteractive'
1027
+ :: Name
1028
+ -> IOEnv
1029
+ (Env TcGblEnv TcLclEnv )
1030
+ (Name ,
1031
+ Either
1032
+ GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
1033
+ getDocsNonInteractive' name =
1025
1034
case nameModule_maybe name of
1026
1035
Nothing -> return (name, Left $ NameHasNoModule name)
1027
1036
Just mod -> do
@@ -1033,7 +1042,7 @@ getDocsNonInteractive name = do
1033
1042
<- loadModuleInterface " getModuleInterface" mod
1034
1043
let
1035
1044
isNameCompiled =
1036
- -- TODO : Find a more direct indicator.
1045
+ -- comment from GHC : Find a more direct indicator.
1037
1046
case nameSrcLoc name of
1038
1047
RealSrcLoc {} -> False
1039
1048
UnhelpfulLoc {} -> True
@@ -1042,20 +1051,26 @@ getDocsNonInteractive name = do
1042
1051
then Left $ NoDocsInIface mod isNameCompiled
1043
1052
else Right (Map. lookup name dmap, Map. lookup name amap)
1044
1053
1054
+ -- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
1055
+ -- The interactive paths create problems in ghc-lib builds
1056
+ --- and lead to fun errors like "Cannot continue after interface file error".
1057
+ getDocsNonInteractive :: HscEnv -> Module -> Name -> IO (Either ErrorMessages (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString ))))
1058
+ getDocsNonInteractive hsc_env mod name = do
1059
+ ((_warns,errs), res) <- initTypecheckEnv hsc_env mod $ getDocsNonInteractive' name
1060
+ pure $ maybeToEither errs res
1061
+
1062
+
1045
1063
-- | Non-interactive, batch version of 'GHC.Runtime.Eval.getDocs'.
1046
1064
getDocsBatch
1047
1065
:: HscEnv
1048
1066
-> Module -- ^ a moudle where the names are in scope
1049
1067
-> [Name ]
1050
1068
-> IO (Either ErrorMessages (Map. Map Name (Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))))
1051
1069
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
1052
- getDocsBatch hsc_env _mod _names = do
1053
- ((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map. fromList <$> traverse getDocsNonInteractive _names
1070
+ getDocsBatch hsc_env mod names = do
1071
+ ((_warns,errs), res) <- initTypecheckEnv hsc_env mod $ Map. fromList <$> traverse getDocsNonInteractive' names
1054
1072
pure $ maybeToEither errs res
1055
1073
1056
- fakeSpan :: RealSrcSpan
1057
- fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util. fsLit " <ghcide>" ) 1 1
1058
-
1059
1074
-- | Non-interactive, batch version of 'InteractiveEval.lookupNames'.
1060
1075
-- The interactive paths create problems in ghc-lib builds
1061
1076
--- and leads to fun errors like "Cannot continue after interface file error".
@@ -1064,7 +1079,7 @@ lookupName :: HscEnv
1064
1079
-> Name
1065
1080
-> IO (Maybe TyThing )
1066
1081
lookupName hsc_env mod name = do
1067
- (_messages, res) <- initTc hsc_env HsSrcFile False mod fakeSpan $ do
1082
+ (_messages, res) <- initTypecheckEnv hsc_env mod $ do
1068
1083
tcthing <- tcLookup name
1069
1084
case tcthing of
1070
1085
AGlobal thing -> return thing
0 commit comments