@@ -1016,39 +1016,42 @@ mkDetailsFromIface session iface linkable = do
1016
1016
initIfaceLoad hsc' (typecheckIface iface)
1017
1017
return (HomeModInfo iface details linkable)
1018
1018
1019
- -- | Non-interactive, batch version of 'InteractiveEval.getDocs'.
1019
+
1020
+ -- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
1020
1021
-- The interactive paths create problems in ghc-lib builds
1021
- --- and leads to fun errors like "Cannot continue after interface file error".
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
1025
+ case nameModule_maybe name of
1026
+ Nothing -> return (name, Left $ NameHasNoModule name)
1027
+ Just mod -> do
1028
+ ModIface
1029
+ { mi_doc_hdr = mb_doc_hdr
1030
+ , mi_decl_docs = DeclDocMap dmap
1031
+ , mi_arg_docs = ArgDocMap amap
1032
+ }
1033
+ <- loadModuleInterface " getModuleInterface" mod
1034
+ let
1035
+ isNameCompiled =
1036
+ -- TODO: Find a more direct indicator.
1037
+ case nameSrcLoc name of
1038
+ RealSrcLoc {} -> False
1039
+ UnhelpfulLoc {} -> True
1040
+ pure . (name,) $
1041
+ if isNothing mb_doc_hdr && Map. null dmap && Map. null amap
1042
+ then Left $ NoDocsInIface mod isNameCompiled
1043
+ else Right (Map. lookup name dmap, Map. lookup name amap)
1044
+
1045
+ -- | Non-interactive, batch version of 'GHC.Runtime.Eval.getDocs'.
1022
1046
getDocsBatch
1023
1047
:: HscEnv
1024
1048
-> Module -- ^ a moudle where the names are in scope
1025
1049
-> [Name ]
1026
1050
-> IO (Either ErrorMessages (Map. Map Name (Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))))
1027
1051
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
1028
1052
getDocsBatch hsc_env _mod _names = do
1029
- ((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map. fromList <$> traverse findNameInfo _names
1053
+ ((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map. fromList <$> traverse getDocsNonInteractive _names
1030
1054
pure $ maybeToEither errs res
1031
- where
1032
- findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv ) (Name , Either GetDocsFailure (Maybe HsDocString , Maybe (Map. Map Int HsDocString )))
1033
- findNameInfo name =
1034
- case nameModule_maybe name of
1035
- Nothing -> return (name, Left $ NameHasNoModule name)
1036
- Just mod -> do
1037
- ModIface
1038
- { mi_doc_hdr = mb_doc_hdr
1039
- , mi_decl_docs = DeclDocMap dmap
1040
- , mi_arg_docs = ArgDocMap amap
1041
- }
1042
- <- loadModuleInterface " getModuleInterface" mod
1043
- pure . (name,) $
1044
- if isNothing mb_doc_hdr && Map. null dmap && Map. null amap
1045
- then Left $ NoDocsInIface mod $ isCompiled name
1046
- else Right (Map. lookup name dmap, Map. lookup name amap)
1047
- isCompiled n =
1048
- -- TODO: Find a more direct indicator.
1049
- case nameSrcLoc n of
1050
- RealSrcLoc {} -> False
1051
- UnhelpfulLoc {} -> True
1052
1055
1053
1056
fakeSpan :: RealSrcSpan
1054
1057
fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util. fsLit " <ghcide>" ) 1 1
0 commit comments