error handling for modules.
This commit is contained in:
parent
93dadfef44
commit
4074c3d751
@ -1,6 +1,7 @@
|
|||||||
module Language.Haskell.GhcMod.List (listModules, modules) where
|
module Language.Haskell.GhcMod.List (listModules, modules) where
|
||||||
|
|
||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
|
import Control.Exception (SomeException(..))
|
||||||
import Control.Monad (void)
|
import Control.Monad (void)
|
||||||
import Data.List (nub, sort)
|
import Data.List (nub, sort)
|
||||||
import GHC (Ghc)
|
import GHC (Ghc)
|
||||||
@ -20,15 +21,17 @@ listModules opt cradle = withGHC' $ do
|
|||||||
|
|
||||||
-- | Listing installed modules.
|
-- | Listing installed modules.
|
||||||
modules :: Options -> Ghc String
|
modules :: Options -> Ghc String
|
||||||
modules opt = convert opt . arrange <$> G.getSessionDynFlags
|
modules opt = convert opt . arrange <$> (getModules `G.gcatch` handler)
|
||||||
where
|
where
|
||||||
arrange = nub . sort . map dropPkgs . getExposedModules
|
getModules = getExposedModules <$> G.getSessionDynFlags
|
||||||
getExposedModules = concatMap exposedModules'
|
getExposedModules = concatMap exposedModules'
|
||||||
. eltsUFM . pkgIdMap . G.pkgState
|
. eltsUFM . pkgIdMap . G.pkgState
|
||||||
exposedModules' p =
|
exposedModules' p =
|
||||||
map G.moduleNameString (exposedModules p)
|
map G.moduleNameString (exposedModules p)
|
||||||
`zip`
|
`zip`
|
||||||
repeat (display $ sourcePackageId p)
|
repeat (display $ sourcePackageId p)
|
||||||
|
arrange = nub . sort . map dropPkgs
|
||||||
dropPkgs (name, pkg)
|
dropPkgs (name, pkg)
|
||||||
| detailed opt = name ++ " " ++ pkg
|
| detailed opt = name ++ " " ++ pkg
|
||||||
| otherwise = name
|
| otherwise = name
|
||||||
|
handler (SomeException _) = return []
|
||||||
|
Loading…
Reference in New Issue
Block a user