ghc-mod/GhcModExe/Modules.hs

28 lines
977 B
Haskell
Raw Normal View History

module GhcModExe.Modules (modules) where
2010-03-11 10:03:17 +00:00
import Control.Arrow
import Data.List
2014-05-11 22:40:00 +00:00
import Language.Haskell.GhcMod.Convert
import Language.Haskell.GhcMod.Types
2014-07-17 05:30:42 +00:00
import Language.Haskell.GhcMod.Monad
import Language.Haskell.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