Skip to content

Commit 5c4926f

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 38463da commit 5c4926f

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
@@ -985,9 +985,33 @@ mkDetailsFromIface session iface linkable = do
985985
initIfaceLoad hsc' (typecheckIface iface)
986986
return (HomeModInfo iface details linkable)
987987

988-
-- | Non-interactive, batch version of 'InteractiveEval.getDocs'.
988+
989+
-- | Non-interactive modification of 'GHC.Runtime.Eval.getDocs'.
989990
-- 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'.
9911015
getDocsBatch
9921016
:: HscEnv
9931017
-> Module -- ^ a moudle where the names are in scope
@@ -996,29 +1020,8 @@ getDocsBatch
9961020
-> IO (Either ErrorMessages (Map.Map Name (Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
9971021
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
9981022
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
10001024
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
10221025

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

0 commit comments

Comments
 (0)