ghc-mod/Browse.hs

31 lines
855 B
Haskell
Raw Normal View History

2010-03-11 10:03:17 +00:00
module Browse (browseModule) where
2010-04-28 06:51:30 +00:00
import Control.Applicative
2010-03-11 10:03:17 +00:00
import Data.Char
import Data.List
2010-04-28 06:51:30 +00:00
import DynFlags
import GHC
import GHC.Paths (libdir)
import Name
2010-03-11 13:39:07 +00:00
import Param
2010-03-11 10:03:17 +00:00
----------------------------------------------------------------
2010-03-11 13:39:07 +00:00
browseModule :: Options -> String -> IO String
2010-04-28 06:51:30 +00:00
browseModule opt mdlName = convert opt . validate <$> browse mdlName
2010-03-11 10:03:17 +00:00
where
2010-04-28 06:51:30 +00:00
validate = sort . filter (isAlpha.head)
2010-03-11 10:03:17 +00:00
2010-04-28 06:51:30 +00:00
browse :: String -> IO [String]
browse mdlName = withGHCAPI (maybeNamesToStrings <$> lookupModuleInfo)
2010-03-11 10:03:17 +00:00
2010-04-27 01:28:00 +00:00
where
lookupModuleInfo = findModule (mkModuleName mdlName) Nothing >>= getModuleInfo
2010-04-28 06:51:30 +00:00
maybeNamesToStrings = maybe [] (map getOccString . modInfoExports)
withGHCAPI :: Ghc a -> IO a
withGHCAPI body = defaultErrorHandler defaultDynFlags $
runGhc (Just libdir) $ do
getSessionDynFlags >>= setSessionDynFlags
body