packageDoc for sandbox.

This commit is contained in:
Kazu Yamamoto 2014-03-27 16:22:49 +09:00
parent 5f6adb53f2
commit 2dd7bab9b2
2 changed files with 25 additions and 0 deletions

View File

@ -23,6 +23,7 @@ module Language.Haskell.GhcMod (
, listFlags
, debugInfo
, rootInfo
, packageDoc
-- * Converting the 'Ghc' monad to the 'IO' monad
, withGHC
, withGHCDummyFile
@ -46,4 +47,5 @@ import Language.Haskell.GhcMod.Info
import Language.Haskell.GhcMod.Lang
import Language.Haskell.GhcMod.Lint
import Language.Haskell.GhcMod.List
import Language.Haskell.GhcMod.PkgDoc
import Language.Haskell.GhcMod.Types

View File

@ -0,0 +1,23 @@
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')