@@ -985,9 +985,33 @@ mkDetailsFromIface session iface linkable = do
985
985
initIfaceLoad hsc' (typecheckIface iface)
986
986
return (HomeModInfo iface details linkable)
987
987
988
- -- | Non-interactive, batch version of 'InteractiveEval.getDocs'.
988
+
989
+ -- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
989
990
-- The interactive paths create problems in ghc-lib builds
990
- --- and leads to fun errors like "Cannot continue after interface file error".
991
+ --- and lead to fun errors like "Cannot continue after interface file error".
992
+ getDocsNonInteractive :: Name -> IOEnv (Env TcGblEnv TcLclEnv ) (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
993
+ getDocsNonInteractive name = do
994
+ case nameModule_maybe name of
995
+ Nothing -> return (name, Left $ NameHasNoModule name)
996
+ Just mod -> do
997
+ ModIface
998
+ { mi_doc_hdr = mb_doc_hdr
999
+ , mi_decl_docs = DeclDocMap dmap
1000
+ , mi_arg_docs = ArgDocMap amap
1001
+ }
1002
+ <- loadModuleInterface " getModuleInterface" mod
1003
+ let
1004
+ isNameCompiled =
1005
+ -- TODO: Find a more direct indicator.
1006
+ case nameSrcLoc name of
1007
+ RealSrcLoc {} -> False
1008
+ UnhelpfulLoc {} -> True
1009
+ pure . (name,) $
1010
+ if isNothing mb_doc_hdr && Map. null dmap && Map. null amap
1011
+ then Left $ NoDocsInIface mod isNameCompiled
1012
+ else Right (Map. lookup name dmap, Map. lookup name amap)
1013
+
1014
+ -- | Non-interactive, batch version of 'GHC.Runtime.Eval.getDocs'.
991
1015
getDocsBatch
992
1016
:: HscEnv
993
1017
-> Module -- ^ a moudle where the names are in scope
@@ -996,29 +1020,8 @@ getDocsBatch
996
1020
-> IO (Either ErrorMessages (Map. Map Name (Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))))
997
1021
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
998
1022
getDocsBatch hsc_env _mod _names = do
999
- ((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map. fromList <$> traverse findNameInfo _names
1023
+ ((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map. fromList <$> traverse getDocsNonInteractive _names
1000
1024
pure $ maybeToEither errs res
1001
- where
1002
- findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv ) (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
1003
- findNameInfo name =
1004
- case nameModule_maybe name of
1005
- Nothing -> return (name, Left $ NameHasNoModule name)
1006
- Just mod -> do
1007
- ModIface
1008
- { mi_doc_hdr = mb_doc_hdr
1009
- , mi_decl_docs = DeclDocMap dmap
1010
- , mi_arg_docs = ArgDocMap amap
1011
- }
1012
- <- loadModuleInterface " getModuleInterface" mod
1013
- pure . (name,) $
1014
- if isNothing mb_doc_hdr && Map. null dmap && Map. null amap
1015
- then Left $ NoDocsInIface mod $ isCompiled name
1016
- else Right (Map. lookup name dmap, Map. lookup name amap)
1017
- isCompiled n =
1018
- -- TODO: Find a more direct indicator.
1019
- case nameSrcLoc n of
1020
- RealSrcLoc {} -> False
1021
- UnhelpfulLoc {} -> True
1022
1025
1023
1026
fakeSpan :: RealSrcSpan
1024
1027
fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util. fsLit " <ghcide>" ) 1 1
0 commit comments