ghc-mod/Language/Haskell/GhcMod/PkgDoc.hs

27 lines
945 B
Haskell
Raw Normal View History

module Language.Haskell.GhcMod.PkgDoc (pkgDoc) where
2014-03-27 07:22:49 +00:00
import CoreMonad (liftIO)
2014-03-27 07:22:49 +00:00
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.GhcPkg
import Language.Haskell.GhcMod.Monad
import Control.Applicative ((<$>))
2014-03-27 07:22:49 +00:00
import System.Process (readProcess)
-- | Obtaining the package name and the doc path of a module.
pkgDoc :: String -> GhcMod String
pkgDoc mdl = cradle >>= \c -> liftIO $ do
pkg <- trim <$> readProcess "ghc-pkg" (toModuleOpts c) []
2014-03-27 07:40:34 +00:00
if pkg == "" then
return "\n"
else do
htmlpath <- readProcess "ghc-pkg" (toDocDirOpts pkg c) []
2014-03-27 07:40:34 +00:00
let ret = pkg ++ " " ++ drop 14 htmlpath
return ret
2014-03-27 07:22:49 +00:00
where
toModuleOpts c = ["find-module", mdl, "--simple-output"]
++ ghcPkgDbStackOpts (cradlePkgDbStack c)
toDocDirOpts pkg c = ["field", pkg, "haddock-html"]
++ ghcPkgDbStackOpts (cradlePkgDbStack c)
trim = takeWhile (`notElem` " \n")