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

31 lines
1012 B
Haskell
Raw Normal View History

2014-03-27 07:22:49 +00:00
module Language.Haskell.GhcMod.PkgDoc (packageDoc) where
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.GhcPkg
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.
packageDoc :: Options
-> Cradle
-> ModuleString
-> IO String
packageDoc _ cradle mdl = pkgDoc cradle mdl
pkgDoc :: Cradle -> String -> IO String
pkgDoc cradle mdl = do
pkg <- trim <$> readProcess "ghc-pkg" toModuleOpts []
2014-03-27 07:40:34 +00:00
if pkg == "" then
return "\n"
else do
htmlpath <- readProcess "ghc-pkg" (toDocDirOpts pkg) []
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 = ["find-module", mdl, "--simple-output"]
++ ghcPkgDbStackOpts (cradlePkgDbStack cradle)
toDocDirOpts pkg = ["field", pkg, "haddock-html"]
++ ghcPkgDbStackOpts (cradlePkgDbStack cradle)
trim = takeWhile (`notElem` " \n")