Skip to content

Commit da99266

Browse files
committed
ghcide: Core.Compile: add getDocsNonInteractive
This function was "inspired" from GHC code of `getDocs`. Since `getDocsBatch` is not really used for batch - only for singleton elements, lets make 1 element processing function & use it.
1 parent 9f4ec33 commit da99266

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -989,9 +989,33 @@ mkDetailsFromIface session iface linkable = do
989989
initIfaceLoad hsc' (typecheckIface iface)
990990
return (HomeModInfo iface details linkable)
991991

992-
-- | Non-interactive, batch version of 'InteractiveEval.getDocs'.
992+
993+
-- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
993994
-- The interactive paths create problems in ghc-lib builds
994-
--- and leads to fun errors like "Cannot continue after interface file error".
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
998+
case nameModule_maybe name of
999+
Nothing -> return (name, Left $ NameHasNoModule name)
1000+
Just mod -> do
1001+
ModIface
1002+
{ mi_doc_hdr = mb_doc_hdr
1003+
, mi_decl_docs = DeclDocMap dmap
1004+
, mi_arg_docs = ArgDocMap amap
1005+
}
1006+
<- loadModuleInterface "getModuleInterface" mod
1007+
let
1008+
isNameCompiled =
1009+
-- TODO: Find a more direct indicator.
1010+
case nameSrcLoc name of
1011+
RealSrcLoc {} -> False
1012+
UnhelpfulLoc {} -> True
1013+
pure . (name,) $
1014+
if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
1015+
then Left $ NoDocsInIface mod isNameCompiled
1016+
else Right (Map.lookup name dmap, Map.lookup name amap)
1017+
1018+
-- | Non-interactive, batch version of 'GHC.Runtime.Eval.getDocs'.
9951019
getDocsBatch
9961020
:: HscEnv
9971021
-> Module -- ^ a moudle where the names are in scope
@@ -1000,30 +1024,8 @@ getDocsBatch
10001024
-> IO (Either ErrorMessages (Map.Map Name (Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
10011025
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
10021026
getDocsBatch hsc_env _mod _names = do
1003-
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map.fromList <$> traverse findNameInfo _names
1027+
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map.fromList <$> traverse getDocsNonInteractive _names
10041028
pure $ maybeToEither errs res
1005-
where
1006-
findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))
1007-
findNameInfo name =
1008-
case nameModule_maybe name of
1009-
Nothing -> return (name, Left $ NameHasNoModule name)
1010-
Just mod -> do
1011-
ModIface
1012-
{ mi_doc_hdr = mb_doc_hdr
1013-
, mi_decl_docs = DeclDocMap dmap
1014-
, mi_arg_docs = ArgDocMap amap
1015-
}
1016-
<- loadModuleInterface "getModuleInterface" mod
1017-
pure . (name,) $
1018-
-- 2021-11-17: NOTE: one does not simply check into Mordor (not 1 mode)
1019-
if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
1020-
then Left $ NoDocsInIface mod $ isCompiled name
1021-
else Right (Map.lookup name dmap, Map.lookup name amap)
1022-
isCompiled n =
1023-
-- TODO: Find a more direct indicator.
1024-
case nameSrcLoc n of
1025-
RealSrcLoc {} -> False
1026-
UnhelpfulLoc {} -> True
10271029

10281030
fakeSpan :: RealSrcSpan
10291031
fakeSpan = realSrcLocSpan $ mkRealSrcLoc (Util.fsLit "<ghcide>") 1 1

0 commit comments

Comments
 (0)