module Haskell.Docs
(module Haskell.Docs
,Identifier(..)
,PackageName(..))
where
import Haskell.Docs.Formatting
import Haskell.Docs.Haddock
import Haskell.Docs.Types
import Control.Monad
import Data.List
import Data.Ord
import GHC hiding (verbosity)
import GhcMonad (liftIO)
searchAndPrintDoc
:: Bool
-> Maybe PackageName
-> Maybe ModuleName
-> Identifier
-> Ghc ()
searchAndPrintDoc ms pname mname ident =
do (result,printPkg,printModule) <- search
case result of
Left err ->
error (show err)
Right (sortBy (comparing identDocPackageName) -> docs) ->
mapM_ (\(i,doc') ->
do when (not ms && i > 0)
(liftIO (putStrLn ""))
printIdentDoc ms printPkg printModule doc')
(zip [0::Int ..] (nub docs))
where search =
case (pname,mname) of
(Just p,Just m) -> fmap (,False,False) (searchPackageModuleIdent Nothing p m ident)
(Nothing,Just m) -> fmap (,True,False) (searchModuleIdent Nothing m ident)
_ -> fmap (,True,True) (searchIdent Nothing ident)