Skip to content

Commit af21b9c

Browse files
committed
Development.IDE.Core.Compile: getDocsBatch: form local fun
1 parent 9a492dd commit af21b9c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ setupFinderCache mss session = do
653653
-- Make modules available for others that import them,
654654
-- by putting them in the finder cache.
655655
let ims = map (installedModule (homeUnitId_ $ hsc_dflags session) . moduleName . ms_mod) mss
656-
ifrs = zipWith (\ms -> InstalledFound (ms_location ms)) mss ims
656+
ifrs = zipWith (InstalledFound . ms_location) mss ims
657657
-- set the target and module graph in the session
658658
graph = mkModuleGraph mss
659659

@@ -967,23 +967,25 @@ getDocsBatch
967967
-> [Name]
968968
-> IO [Either String (Maybe HsDocString, Map.Map Int HsDocString)]
969969
getDocsBatch hsc_env _mod _names = do
970-
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ forM _names $ \name ->
970+
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ traverse findNameInfo _names
971+
case res of
972+
Just x -> return $ map (first $ T.unpack . showGhc) x
973+
Nothing -> throwErrors errs
974+
where
975+
throwErrors = liftIO . throwIO . mkSrcErr
976+
977+
findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Either GetDocsFailure (Maybe HsDocString, Map.Map Int HsDocString))
978+
findNameInfo name =
971979
case nameModule_maybe name of
972980
Nothing -> return (Left $ NameHasNoModule name)
973981
Just mod -> do
974982
ModIface { mi_doc_hdr = mb_doc_hdr
975983
, mi_decl_docs = DeclDocMap dmap
976984
, mi_arg_docs = ArgDocMap amap
977985
} <- loadModuleInterface "getModuleInterface" mod
978-
if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
979-
then pure (Left (NoDocsInIface mod $ compiled name))
980-
else pure (Right ( Map.lookup name dmap
981-
, Map.findWithDefault Map.empty name amap))
982-
case res of
983-
Just x -> return $ map (first $ T.unpack . showGhc) x
984-
Nothing -> throwErrors errs
985-
where
986-
throwErrors = liftIO . throwIO . mkSrcErr
986+
pure $ if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
987+
then Left (NoDocsInIface mod $ compiled name)
988+
else Right (Map.lookup name dmap, Map.findWithDefault mempty name amap)
987989
compiled n =
988990
-- TODO: Find a more direct indicator.
989991
case nameSrcLoc n of

0 commit comments

Comments
 (0)