Skip to content

Commit 0a5900d

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 5192cfb commit 0a5900d

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,39 +1016,42 @@ mkDetailsFromIface session iface linkable = do
10161016
initIfaceLoad hsc' (typecheckIface iface)
10171017
return (HomeModInfo iface details linkable)
10181018

1019-
-- | Non-interactive, batch version of 'InteractiveEval.getDocs'.
1019+
1020+
-- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
10201021
-- 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'.
10221046
getDocsBatch
10231047
:: HscEnv
10241048
-> Module -- ^ a moudle where the names are in scope
10251049
-> [Name]
10261050
-> IO (Either ErrorMessages (Map.Map Name (Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
10271051
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
10281052
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
10301054
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
10521055

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

0 commit comments

Comments
 (0)