2017-01-12 15:36:47 +00:00
|
|
|
module GhcMod.PkgDoc (pkgDoc) where
|
2014-03-27 07:22:49 +00:00
|
|
|
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2014-04-15 03:13:10 +00:00
|
|
|
import Language.Haskell.GhcMod.GhcPkg
|
2014-07-11 01:10:37 +00:00
|
|
|
import Language.Haskell.GhcMod.Monad
|
2015-09-02 05:19:11 +00:00
|
|
|
import Language.Haskell.GhcMod.Output
|
2014-04-15 03:13:10 +00:00
|
|
|
|
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.
|
2014-07-12 09:16:16 +00:00
|
|
|
pkgDoc :: IOish m => String -> GhcModT m String
|
2014-08-31 21:08:04 +00:00
|
|
|
pkgDoc mdl = do
|
2015-09-02 05:19:11 +00:00
|
|
|
ghcPkg <- getGhcPkgProgram
|
|
|
|
readProc <- gmReadProcess
|
2015-08-07 04:47:34 +00:00
|
|
|
pkgDbStack <- getPackageDbStack
|
2015-09-02 05:19:11 +00:00
|
|
|
pkg <- liftIO $ trim <$> readProc ghcPkg (toModuleOpts pkgDbStack) ""
|
2014-03-27 07:40:34 +00:00
|
|
|
if pkg == "" then
|
|
|
|
return "\n"
|
|
|
|
else do
|
2015-09-02 05:19:11 +00:00
|
|
|
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
|
2015-08-07 04:47:34 +00:00
|
|
|
toModuleOpts dbs = ["find-module", mdl, "--simple-output"]
|
|
|
|
++ ghcPkgDbStackOpts dbs
|
|
|
|
toDocDirOpts pkg dbs = ["field", pkg, "haddock-html"]
|
|
|
|
++ ghcPkgDbStackOpts dbs
|
2014-03-30 03:37:29 +00:00
|
|
|
trim = takeWhile (`notElem` " \n")
|