ghc-mod/Language/Haskell/GhcMod/Modules.hs

33 lines
1.1 KiB
Haskell
Raw Normal View History

2014-08-28 09:41:03 +00:00
module Language.Haskell.GhcMod.Modules (modules) where
2010-03-11 10:03:17 +00:00
2014-03-27 07:02:16 +00:00
import Control.Applicative ((<$>))
2014-04-24 03:51:43 +00:00
import Control.Exception (SomeException(..))
2014-03-27 07:02:16 +00:00
import Data.List (nub, sort)
import qualified GHC as G
2014-05-11 22:40:00 +00:00
import Language.Haskell.GhcMod.Convert
2014-07-17 05:30:42 +00:00
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Types
2014-03-27 07:02:16 +00:00
import Packages (pkgIdMap, exposedModules, sourcePackageId, display)
import UniqFM (eltsUFM)
2010-03-11 10:03:17 +00:00
----------------------------------------------------------------
2013-05-20 05:28:56 +00:00
-- | Listing installed modules.
modules :: IOish m => GhcModT m String
2014-05-10 11:51:35 +00:00
modules = do
opt <- options
2014-07-17 08:16:44 +00:00
convert opt . arrange opt <$> (getModules `G.gcatch` handler)
2010-03-11 10:03:17 +00:00
where
2014-04-24 03:51:43 +00:00
getModules = getExposedModules <$> G.getSessionDynFlags
2013-10-28 08:22:18 +00:00
getExposedModules = concatMap exposedModules'
2014-03-27 07:02:16 +00:00
. eltsUFM . pkgIdMap . G.pkgState
2013-10-28 08:22:18 +00:00
exposedModules' p =
2014-03-27 07:02:16 +00:00
map G.moduleNameString (exposedModules p)
2013-10-28 08:22:18 +00:00
`zip`
2014-03-27 07:02:16 +00:00
repeat (display $ sourcePackageId p)
2014-05-10 11:51:35 +00:00
arrange opt = nub . sort . map (dropPkgs opt)
dropPkgs opt (name, pkg)
2014-04-21 03:46:14 +00:00
| detailed opt = name ++ " " ++ pkg
| otherwise = name
2014-04-24 03:51:43 +00:00
handler (SomeException _) = return []