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