2014-03-27 07:22:49 +00:00
|
|
|
module Language.Haskell.GhcMod.PkgDoc (packageDoc) where
|
|
|
|
|
|
|
|
import Control.Applicative ((<$>))
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2014-03-28 03:05:11 +00:00
|
|
|
import Language.Haskell.GhcMod.Cradle
|
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
|
2014-03-28 03:05:11 +00:00
|
|
|
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
|
2014-03-28 03:05:11 +00:00
|
|
|
toModuleOpts = ["find-module", mdl, "--simple-output"] ++ userPackageDbOptsForGhcPkg (cradlePackageDb cradle)
|
|
|
|
toDocDirOpts pkg = ["field", pkg, "haddock-html"] ++ userPackageDbOptsForGhcPkg (cradlePackageDb cradle)
|
2014-03-30 03:37:29 +00:00
|
|
|
trim = takeWhile (`notElem` " \n")
|