ghc-mod/GhcMod/Exe/Modules.hs

28 lines
910 B
Haskell
Raw Permalink Normal View History

module GhcMod.Exe.Modules (modules) where
2010-03-11 10:03:17 +00:00
import Control.Arrow
import Data.List
import GhcMod.Convert
import GhcMod.Types
import GhcMod.Monad
import GhcMod.Gap ( listVisibleModuleNames
, lookupModulePackageInAllPackages
)
import qualified GHC as G
2010-03-11 10:03:17 +00:00
----------------------------------------------------------------
2013-05-20 05:28:56 +00:00
-- | Listing installed modules.
2015-12-07 16:57:33 +00:00
modules :: (IOish m, Gm m)
=> Bool -- ^ 'detailed', if 'True', also prints packages that modules belong to.
-> m String
2015-12-05 20:55:12 +00:00
modules detailed = do
df <- runGmPkgGhc G.getSessionDynFlags
let mns = listVisibleModuleNames df
pmnss = map (first moduleNameString) $ zip mns (modulePkg df `map` mns)
2015-12-05 20:55:12 +00:00
convert' $ nub [ if detailed then pkg ++ " " ++ mn else mn
| (mn, pkgs) <- pmnss, pkg <- pkgs ]
where
modulePkg df = lookupModulePackageInAllPackages df