Skip to content

Commit a06846b

Browse files
committed
Development.IDE.Core.Compile: getDocsBatch: return (Name,)
The types show it needs be such. The semantics of code in funciton show it needs be such. The use of the function shows it needs to be such. `zipWithM .. names` would not be needed.
1 parent af21b9c commit a06846b

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -965,27 +965,37 @@ getDocsBatch
965965
:: HscEnv
966966
-> Module -- ^ a moudle where the names are in scope
967967
-> [Name]
968-
-> IO [Either String (Maybe HsDocString, Map.Map Int HsDocString)]
968+
-> IO [(Name, Either String (Maybe HsDocString, Map.Map Int HsDocString))]
969969
getDocsBatch hsc_env _mod _names = do
970970
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ traverse findNameInfo _names
971971
case res of
972-
Just x -> return $ map (first $ T.unpack . showGhc) x
972+
Just x -> return $ fun x
973973
Nothing -> throwErrors errs
974974
where
975+
fun :: [(Name, Either GetDocsFailure c)] -> [(Name, Either String c)]
976+
fun =
977+
map fun1
978+
where
979+
fun1 :: ((Name, Either GetDocsFailure c) -> (Name, Either String c))
980+
fun1 = fmap (first $ T.unpack . showGhc)
981+
975982
throwErrors = liftIO . throwIO . mkSrcErr
976983

977-
findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Either GetDocsFailure (Maybe HsDocString, Map.Map Int HsDocString))
984+
findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, Either GetDocsFailure (Maybe HsDocString, Map.Map Int HsDocString))
978985
findNameInfo name =
979986
case nameModule_maybe name of
980-
Nothing -> return (Left $ NameHasNoModule name)
987+
Nothing -> return (name, Left $ NameHasNoModule name)
981988
Just mod -> do
982-
ModIface { mi_doc_hdr = mb_doc_hdr
983-
, mi_decl_docs = DeclDocMap dmap
984-
, mi_arg_docs = ArgDocMap amap
985-
} <- loadModuleInterface "getModuleInterface" mod
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)
989+
ModIface
990+
{ mi_doc_hdr = mb_doc_hdr
991+
, mi_decl_docs = DeclDocMap dmap
992+
, mi_arg_docs = ArgDocMap amap
993+
}
994+
<- loadModuleInterface "getModuleInterface" mod
995+
pure . (name,) $
996+
if isNothing mb_doc_hdr && Map.null dmap && Map.null amap
997+
then Left $ NoDocsInIface mod $ compiled name
998+
else Right (Map.lookup name dmap, Map.findWithDefault mempty name amap)
989999
compiled n =
9901000
-- TODO: Find a more direct indicator.
9911001
case nameSrcLoc n of

ghcide/src/Development/IDE/Spans/Documentation.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ getDocumentationTryGhc env mod n = head <$> getDocumentationsTryGhc env mod [n]
6767

6868
getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO [SpanDoc]
6969
getDocumentationsTryGhc env mod names = do
70-
res <- catchSrcErrors (hsc_dflags env) "docs" $ getDocsBatch env mod names
70+
res <- catchSrcErrors (hsc_dflags env) "docs" $ (fmap . fmap) snd $ getDocsBatch env mod names
7171
case res of
7272
Left _ -> return []
7373
Right res -> zipWithM unwrap res names

0 commit comments

Comments
 (0)