ghc-mod/Language/Haskell/GhcMod/PkgDoc.hs
2014-03-27 16:22:49 +09:00

24 lines
756 B
Haskell

module Language.Haskell.GhcMod.PkgDoc (packageDoc) where
import Control.Applicative ((<$>))
import Language.Haskell.GhcMod.Types
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 []
htmlpath <- readProcess "ghc-pkg" ["field", pkg, "haddock-html"] []
let ret = pkg ++ " " ++ drop 14 htmlpath
return ret
where
toModuleOpts = ["find-module", "--simple-output"] ++ cradlePackageDbOpts cradle ++ [mdl]
trim = fst . break (== '\n')