2013-05-20 05:28:56 +00:00
|
|
|
module Language.Haskell.GhcMod.List (listModules, listMods) where
|
2010-03-11 10:03:17 +00:00
|
|
|
|
|
|
|
import Control.Applicative
|
2013-09-27 03:23:53 +00:00
|
|
|
import Control.Monad (void)
|
2010-03-11 10:03:17 +00:00
|
|
|
import Data.List
|
2010-04-30 09:17:20 +00:00
|
|
|
import GHC
|
2013-05-17 01:00:01 +00:00
|
|
|
import Language.Haskell.GhcMod.GHCApi
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2010-04-30 09:17:20 +00:00
|
|
|
import Packages
|
|
|
|
import UniqFM
|
2010-03-11 10:03:17 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2013-05-20 05:28:56 +00:00
|
|
|
-- | Listing installed modules.
|
2013-09-27 03:23:53 +00:00
|
|
|
listModules :: Options -> Cradle -> IO String
|
2013-10-29 02:32:06 +00:00
|
|
|
listModules opt cradle = convert opt . nub . sort . map dropPkgs <$> withGHCDummyFile (listMods opt cradle)
|
|
|
|
where
|
|
|
|
dropPkgs (name, pkg)
|
|
|
|
| detailed opt = name ++ " " ++ pkg
|
|
|
|
| otherwise = name
|
2010-03-11 10:03:17 +00:00
|
|
|
|
2013-05-20 05:28:56 +00:00
|
|
|
-- | Listing installed modules.
|
2013-10-29 02:32:06 +00:00
|
|
|
listMods :: Options -> Cradle -> Ghc [(String, String)]
|
2013-09-27 03:23:53 +00:00
|
|
|
listMods opt cradle = do
|
|
|
|
void $ initializeFlagsWithCradle opt cradle [] False
|
2010-04-30 09:17:20 +00:00
|
|
|
getExposedModules <$> getSessionDynFlags
|
2010-03-11 10:03:17 +00:00
|
|
|
where
|
2013-10-28 08:22:18 +00:00
|
|
|
getExposedModules = concatMap exposedModules'
|
2010-04-30 09:36:31 +00:00
|
|
|
. eltsUFM . pkgIdMap . pkgState
|
2013-10-28 08:22:18 +00:00
|
|
|
exposedModules' p =
|
|
|
|
map moduleNameString (exposedModules p)
|
|
|
|
`zip`
|
|
|
|
repeat (display $ sourcePackageId p)
|