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