ghc-mod/List.hs

26 lines
719 B
Haskell
Raw Normal View History

2010-03-11 10:03:17 +00:00
module List (listModules) where
import Control.Applicative
import Data.List
2010-04-30 09:17:20 +00:00
import Exception
import GHC
import GHC.Paths (libdir)
import Packages
2010-03-11 13:39:07 +00:00
import Param
2010-04-30 09:17:20 +00:00
import UniqFM
2010-03-11 10:03:17 +00:00
----------------------------------------------------------------
2010-03-11 13:39:07 +00:00
listModules :: Options -> IO String
2010-04-30 09:17:20 +00:00
listModules opt = convert opt . nub . sort <$> getModules
2010-03-11 10:03:17 +00:00
2010-04-30 09:17:20 +00:00
getModules :: IO [String]
getModules = ghandle ignore $ runGhc (Just libdir) $ do
initSession
getExposedModules <$> getSessionDynFlags
2010-03-11 10:03:17 +00:00
where
2010-04-30 09:17:20 +00:00
initSession = getSessionDynFlags >>= setSessionDynFlags
getExposedModules = map moduleNameString . concatMap exposedModules . eltsUFM . pkgIdMap . pkgState
ignore :: SomeException -> IO [String]
ignore _ = return []