f0bfcb8811
Not doing this makes having GhcModT pretty pointless as users of the library wouldn't be able to use custom inner monads as evey function for dealing with GhcModT's would be constraint to (GhcModT IO) thus only allowing IO as the inner monad.
33 lines
1.1 KiB
Haskell
33 lines
1.1 KiB
Haskell
module Language.Haskell.GhcMod.List (modules) where
|
|
|
|
import Control.Applicative ((<$>))
|
|
import Control.Exception (SomeException(..))
|
|
import Data.List (nub, sort)
|
|
import qualified GHC as G
|
|
import Language.Haskell.GhcMod.Monad
|
|
import Language.Haskell.GhcMod.Convert
|
|
import Language.Haskell.GhcMod.Types
|
|
import Packages (pkgIdMap, exposedModules, sourcePackageId, display)
|
|
import UniqFM (eltsUFM)
|
|
|
|
----------------------------------------------------------------
|
|
|
|
-- | Listing installed modules.
|
|
modules :: IOish m => GhcModT m String
|
|
modules = do
|
|
opt <- options
|
|
convert opt . (arrange opt) <$> (getModules `G.gcatch` handler)
|
|
where
|
|
getModules = getExposedModules <$> G.getSessionDynFlags
|
|
getExposedModules = concatMap exposedModules'
|
|
. eltsUFM . pkgIdMap . G.pkgState
|
|
exposedModules' p =
|
|
map G.moduleNameString (exposedModules p)
|
|
`zip`
|
|
repeat (display $ sourcePackageId p)
|
|
arrange opt = nub . sort . map (dropPkgs opt)
|
|
dropPkgs opt (name, pkg)
|
|
| detailed opt = name ++ " " ++ pkg
|
|
| otherwise = name
|
|
handler (SomeException _) = return []
|