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

30 lines
1007 B
Haskell
Raw Normal View History

module Language.Haskell.GhcMod.PkgDoc (pkgDoc) where
2014-03-27 07:22:49 +00:00
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.GhcPkg
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Output
2015-08-03 01:09:56 +00:00
import Control.Applicative
import Prelude
2014-03-27 07:22:49 +00:00
-- | Obtaining the package name and the doc path of a module.
pkgDoc :: IOish m => String -> GhcModT m String
2014-08-31 21:08:04 +00:00
pkgDoc mdl = do
ghcPkg <- getGhcPkgProgram
readProc <- gmReadProcess
pkgDbStack <- getPackageDbStack
pkg <- liftIO $ trim <$> readProc ghcPkg (toModuleOpts pkgDbStack) ""
2014-03-27 07:40:34 +00:00
if pkg == "" then
return "\n"
else do
htmlpath <- liftIO $ readProc ghcPkg (toDocDirOpts pkg pkgDbStack) ""
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 dbs = ["find-module", mdl, "--simple-output"]
++ ghcPkgDbStackOpts dbs
toDocDirOpts pkg dbs = ["field", pkg, "haddock-html"]
++ ghcPkgDbStackOpts dbs
trim = takeWhile (`notElem` " \n")