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