export minimum Monad stuff from GhcMod.
This commit is contained in:
parent
e1d9c3b881
commit
30ddd655cd
@ -15,7 +15,12 @@ module Language.Haskell.GhcMod (
|
|||||||
, GhcPkgDb
|
, GhcPkgDb
|
||||||
, Symbol
|
, Symbol
|
||||||
, SymbolDb
|
, SymbolDb
|
||||||
, module Language.Haskell.GhcMod.Monad
|
-- * Monad Types
|
||||||
|
, GhcModT
|
||||||
|
, IOish
|
||||||
|
-- * Monad utilities
|
||||||
|
, runGhcModT
|
||||||
|
, withOptions
|
||||||
-- * 'GhcMod' utilities
|
-- * 'GhcMod' utilities
|
||||||
, boot
|
, boot
|
||||||
, browse
|
, browse
|
||||||
|
@ -79,7 +79,7 @@ withLogger setDF body = ghandle sourceError $ do
|
|||||||
sourceError :: IOish m => SourceError -> GhcModT m (Either String String)
|
sourceError :: IOish m => SourceError -> GhcModT m (Either String String)
|
||||||
sourceError err = do
|
sourceError err = do
|
||||||
dflags <- G.getSessionDynFlags
|
dflags <- G.getSessionDynFlags
|
||||||
style <- toGhcMod getStyle
|
style <- toGhcModT getStyle
|
||||||
ret <- convert' (errBagToStrList dflags style . srcErrorMessages $ err)
|
ret <- convert' (errBagToStrList dflags style . srcErrorMessages $ err)
|
||||||
return $ Left ret
|
return $ Left ret
|
||||||
|
|
||||||
|
@ -23,12 +23,13 @@ module Language.Haskell.GhcMod.Monad (
|
|||||||
, withErrorHandler
|
, withErrorHandler
|
||||||
-- ** Conversion
|
-- ** Conversion
|
||||||
, liftGhcMod
|
, liftGhcMod
|
||||||
, toGhcMod
|
, toGhcModT
|
||||||
-- ** Accessing 'GhcModEnv' and 'GhcModState'
|
-- ** Accessing 'GhcModEnv' and 'GhcModState'
|
||||||
, options
|
, options
|
||||||
, cradle
|
, cradle
|
||||||
, getMode
|
, getMode
|
||||||
, setMode
|
, setMode
|
||||||
|
, withOptions
|
||||||
-- ** Exporting convenient modules
|
-- ** Exporting convenient modules
|
||||||
, module Control.Monad.Reader.Class
|
, module Control.Monad.Reader.Class
|
||||||
, module Control.Monad.Writer.Class
|
, module Control.Monad.Writer.Class
|
||||||
@ -274,8 +275,8 @@ withErrorHandler label = ghandle ignore
|
|||||||
exitSuccess
|
exitSuccess
|
||||||
|
|
||||||
-- | This is only a transitional mechanism don't use it for new code.
|
-- | This is only a transitional mechanism don't use it for new code.
|
||||||
toGhcMod :: IOish m => Ghc a -> GhcModT m a
|
toGhcModT :: IOish m => Ghc a -> GhcModT m a
|
||||||
toGhcMod a = do
|
toGhcModT a = do
|
||||||
s <- gmGhcSession <$> ask
|
s <- gmGhcSession <$> ask
|
||||||
liftIO $ unGhc a $ Session s
|
liftIO $ unGhc a $ Session s
|
||||||
|
|
||||||
@ -297,6 +298,15 @@ setMode mode = put $ GhcModState mode
|
|||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
withOptions :: IOish m => (Options -> Options) -> GhcModT m a -> GhcModT m a
|
||||||
|
withOptions changeOpt action = local changeEnv action
|
||||||
|
where
|
||||||
|
changeEnv e = e { gmOptions = changeOpt opt }
|
||||||
|
where
|
||||||
|
opt = gmOptions e
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
instance (MonadBaseControl IO m) => MonadBase IO (GhcModT m) where
|
instance (MonadBaseControl IO m) => MonadBase IO (GhcModT m) where
|
||||||
liftBase = GhcModT . liftBase
|
liftBase = GhcModT . liftBase
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ import Data.Set (Set)
|
|||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Data.Typeable (Typeable)
|
import Data.Typeable (Typeable)
|
||||||
import Data.Version (showVersion)
|
import Data.Version (showVersion)
|
||||||
import GHC (GhcMonad)
|
|
||||||
import qualified GHC as G
|
import qualified GHC as G
|
||||||
import Language.Haskell.GhcMod
|
import Language.Haskell.GhcMod
|
||||||
import Paths_ghc_mod
|
import Paths_ghc_mod
|
||||||
@ -151,14 +150,14 @@ checkStx :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
checkStx set file = do
|
checkStx set file = do
|
||||||
set' <- toGhcMod $ newFileSet set file
|
set' <- newFileSet set file
|
||||||
let files = S.toList set'
|
let files = S.toList set'
|
||||||
eret <- check files
|
eret <- check files
|
||||||
case eret of
|
case eret of
|
||||||
Right ret -> return (ret, True, set')
|
Right ret -> return (ret, True, set')
|
||||||
Left ret -> return (ret, True, set) -- fxime: set
|
Left ret -> return (ret, True, set) -- fxime: set
|
||||||
|
|
||||||
newFileSet :: GhcMonad m => Set FilePath -> FilePath -> m (Set FilePath)
|
newFileSet :: IOish m => Set FilePath -> FilePath -> GhcModT m (Set FilePath)
|
||||||
newFileSet set file = do
|
newFileSet set file = do
|
||||||
let set1
|
let set1
|
||||||
| S.member file set = set
|
| S.member file set = set
|
||||||
@ -168,7 +167,7 @@ newFileSet set file = do
|
|||||||
Nothing -> set1
|
Nothing -> set1
|
||||||
Just mainfile -> S.delete mainfile set1
|
Just mainfile -> S.delete mainfile set1
|
||||||
|
|
||||||
getModSummaryForMain :: GhcMonad m => m (Maybe G.ModSummary)
|
getModSummaryForMain :: IOish m => GhcModT m (Maybe G.ModSummary)
|
||||||
getModSummaryForMain = find isMain <$> G.getModuleGraph
|
getModSummaryForMain = find isMain <$> G.getModuleGraph
|
||||||
where
|
where
|
||||||
isMain m = G.moduleNameString (G.moduleName (G.ms_mod m)) == "Main"
|
isMain m = G.moduleNameString (G.moduleName (G.ms_mod m)) == "Main"
|
||||||
@ -197,13 +196,12 @@ lintStx :: IOish m => Set FilePath
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
lintStx set optFile = do
|
lintStx set optFile = do
|
||||||
ret <- local env' $ lint file
|
ret <- withOptions changeOpt $ lint file
|
||||||
return (ret, True, set)
|
return (ret, True, set)
|
||||||
where
|
where
|
||||||
(opts,file) = parseLintOptions optFile
|
(opts,file) = parseLintOptions optFile
|
||||||
hopts = if opts == "" then [] else read opts
|
hopts = if opts == "" then [] else read opts
|
||||||
env' e = e { gmOptions = opt' $ gmOptions e }
|
changeOpt o = o { hlintOpts = hopts }
|
||||||
opt' o = o { hlintOpts = hopts }
|
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- >>> parseLintOptions "[\"--ignore=Use camelCase\", \"--ignore=Eta reduce\"] file name"
|
-- >>> parseLintOptions "[\"--ignore=Use camelCase\", \"--ignore=Eta reduce\"] file name"
|
||||||
|
Loading…
Reference in New Issue
Block a user