cleaning up APIs.

This commit is contained in:
Kazu Yamamoto 2014-04-21 12:46:14 +09:00
parent 064e4af236
commit 2f55a19d49
3 changed files with 12 additions and 13 deletions

View File

@ -32,7 +32,7 @@ module Language.Haskell.GhcMod (
, check
, info
, typeOf
, listMods
, modules
, lint
) where

View File

@ -31,7 +31,7 @@ browseModule :: Options
-> Cradle
-> ModuleString -- ^ A module name. (e.g. \"Data.List\")
-> IO String
browseModule opt cradle mdlName = convert opt . sort <$> withGHCDummyFile (browse opt cradle mdlName)
browseModule opt cradle mdlName = withGHCDummyFile (browse opt cradle mdlName)
-- | Getting functions, classes, etc from a module.
-- If 'detailed' is 'True', their types are also obtained.
@ -39,10 +39,10 @@ browseModule opt cradle mdlName = convert opt . sort <$> withGHCDummyFile (brows
browse :: Options
-> Cradle
-> ModuleString -- ^ A module name. (e.g. \"Data.List\")
-> Ghc [String]
-> Ghc String
browse opt cradle mdlName = do
void $ initializeFlagsWithCradle opt cradle [] False
getModule >>= G.getModuleInfo >>= listExports
convert opt . sort <$> (getModule >>= G.getModuleInfo >>= listExports)
where
getModule = G.findModule mdlname mpkgid `G.gcatch` fallback
mdlname = G.mkModuleName mdlName

View File

@ -1,4 +1,4 @@
module Language.Haskell.GhcMod.List (listModules, listMods) where
module Language.Haskell.GhcMod.List (listModules, modules) where
import Control.Applicative ((<$>))
import Control.Monad (void)
@ -14,17 +14,13 @@ import UniqFM (eltsUFM)
-- | Listing installed modules.
listModules :: Options -> Cradle -> IO String
listModules opt cradle = convert opt . nub . sort . map dropPkgs <$> withGHCDummyFile (listMods opt cradle)
where
dropPkgs (name, pkg)
| detailed opt = name ++ " " ++ pkg
| otherwise = name
listModules opt cradle = withGHCDummyFile (modules opt cradle)
-- | Listing installed modules.
listMods :: Options -> Cradle -> Ghc [(String, String)]
listMods opt cradle = do
modules :: Options -> Cradle -> Ghc String
modules opt cradle = do
void $ initializeFlagsWithCradle opt cradle [] False
getExposedModules <$> G.getSessionDynFlags
convert opt . nub . sort . map dropPkgs . getExposedModules <$> G.getSessionDynFlags
where
getExposedModules = concatMap exposedModules'
. eltsUFM . pkgIdMap . G.pkgState
@ -32,3 +28,6 @@ listMods opt cradle = do
map G.moduleNameString (exposedModules p)
`zip`
repeat (display $ sourcePackageId p)
dropPkgs (name, pkg)
| detailed opt = name ++ " " ++ pkg
| otherwise = name