From 38a3e32ac3f8e9f309302b06899f221bba129d3d Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 25 Mar 2014 11:14:16 +0900 Subject: [PATCH] browseAll. --- Language/Haskell/GhcMod/Browse.hs | 24 ++++++++++++++++++++++-- Language/Haskell/GhcMod/Internal.hs | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Language/Haskell/GhcMod/Browse.hs b/Language/Haskell/GhcMod/Browse.hs index 76801a4..0078e3f 100644 --- a/Language/Haskell/GhcMod/Browse.hs +++ b/Language/Haskell/GhcMod/Browse.hs @@ -1,4 +1,8 @@ -module Language.Haskell.GhcMod.Browse (browseModule, browse) where +module Language.Haskell.GhcMod.Browse ( + browseModule + , browse + , browseAll) + where import Control.Applicative import Control.Monad (void) @@ -7,7 +11,7 @@ import Data.List import Data.Maybe (catMaybes) import FastString (mkFastString) import GHC -import Language.Haskell.GhcMod.Doc (showUnqualifiedPage) +import Language.Haskell.GhcMod.Doc (showUnqualifiedPage, showUnqualifiedOneLine) import Language.Haskell.GhcMod.GHCApi import Language.Haskell.GhcMod.Gap import Language.Haskell.GhcMod.Types @@ -126,3 +130,19 @@ removeForAlls' ty (Just (pre, ftype)) showOutputable :: Outputable a => DynFlags -> a -> String showOutputable dflag = unwords . lines . showUnqualifiedPage dflag . ppr + +---------------------------------------------------------------- + +browseAll :: DynFlags -> Ghc [(String,String)] +browseAll dflag = do + ms <- packageDbModules True + is <- mapM getModuleInfo ms + return $ concatMap (toNameModule dflag) (zip ms is) + +toNameModule :: DynFlags -> (Module, Maybe ModuleInfo) -> [(String,String)] +toNameModule _ (_,Nothing) = [] +toNameModule dflag (m,Just inf) = map (\name -> (toStr name, mdl)) names + where + mdl = moduleNameString (moduleName m) + names = modInfoExports inf + toStr = showUnqualifiedOneLine dflag . ppr diff --git a/Language/Haskell/GhcMod/Internal.hs b/Language/Haskell/GhcMod/Internal.hs index e571cb1..74bf262 100644 --- a/Language/Haskell/GhcMod/Internal.hs +++ b/Language/Haskell/GhcMod/Internal.hs @@ -31,8 +31,10 @@ module Language.Haskell.GhcMod.Internal ( , (|||>) -- * GHC , getSystemLibDir + , browseAll ) where +import Language.Haskell.GhcMod.Browse import Language.Haskell.GhcMod.CabalApi import Language.Haskell.GhcMod.ErrMsg import Language.Haskell.GhcMod.GHCApi