82bb0090c0
This turned out to be quite involved but save for this huge commit it's actually quite awesome and squashes quite a few bugs and nasty problems (hopefully). Most importantly we now have native cabal component support without the user having to do anything to get it! To do this we traverse imports starting from each component's entrypoints (library modules or Main source file for executables) and use this information to find which component's options each module will build with. Under the assumption that these modules have to build with every component they're used in we can now just pick one. Quite a few internal assumptions have been invalidated by this change. Most importantly the runGhcModT* family of cuntions now change the current working directory to `cradleRootDir`.
27 lines
942 B
Haskell
27 lines
942 B
Haskell
module Language.Haskell.GhcMod.PkgDoc (pkgDoc) where
|
|
|
|
import Language.Haskell.GhcMod.Types
|
|
import Language.Haskell.GhcMod.GhcPkg
|
|
import Language.Haskell.GhcMod.Monad
|
|
import Language.Haskell.GhcMod.Utils
|
|
|
|
import Control.Applicative ((<$>))
|
|
|
|
-- | Obtaining the package name and the doc path of a module.
|
|
pkgDoc :: IOish m => String -> GhcModT m String
|
|
pkgDoc mdl = do
|
|
c <- cradle
|
|
pkg <- liftIO $ trim <$> readProcess "ghc-pkg" (toModuleOpts c) ""
|
|
if pkg == "" then
|
|
return "\n"
|
|
else do
|
|
htmlpath <- liftIO $ readProcess "ghc-pkg" (toDocDirOpts pkg c) ""
|
|
let ret = pkg ++ " " ++ drop 14 htmlpath
|
|
return ret
|
|
where
|
|
toModuleOpts c = ["find-module", mdl, "--simple-output"]
|
|
++ ghcPkgDbStackOpts (cradlePkgDbStack c)
|
|
toDocDirOpts pkg c = ["field", pkg, "haddock-html"]
|
|
++ ghcPkgDbStackOpts (cradlePkgDbStack c)
|
|
trim = takeWhile (`notElem` " \n")
|