Language.Haskell.GhcMod.Monad.Types

ghc-mod-5.5.0.0: Happy Haskell Programming

Safe Haskell | None
Language | Haskell2010

Language.Haskell.GhcMod.Monad.Types

Contents

- Monad Types
- Environment, state and logging
- Accessing `GhcModEnv`, `GhcModState` and `GhcModLog`
- Re-exporting convenient stuff

Synopsis

- type GhcModT m = GmT (GmOutT m)
- newtype GmOutT m a = GmOutT {
  - unGmOutT :: ReaderT GhcModOut m a
  }
- newtype GmT m a = GmT {
  - unGmT :: StateT GhcModState (ErrorT GhcModError (JournalT GhcModLog (ReaderT GhcModEnv m))) a
  }
- newtype GmlT m a = GmlT {
  - unGmlT :: GhcModT m a
  }
- newtype LightGhc a = LightGhc {
  - unLightGhc :: ReaderT (IORef HscEnv) IO a
  }
- type GmGhc m = (IOish m, GhcMonad m)
- type IOish m = (Functor m, MonadIO m, MonadBaseControl IO m, ExceptionMonad m)
- data GhcModEnv = GhcModEnv {
  - gmOptions :: Options
  - gmCradle :: Cradle
  }
- data GhcModState = GhcModState {
  - gmGhcSession :: !(Maybe GmGhcSession)
  - gmCaches :: !GhcModCaches
  - gmMMappedFiles :: !FileMappingMap
  }
- data GhcModCaches = GhcModCaches {
  - gmcPackageDbStack :: CacheContents ChCacheData [GhcPkgDb]
  - gmcMergedPkgOptions :: CacheContents ChCacheData [GHCOption]
  - gmcComponents :: CacheContents ChCacheData [GmComponent GMCRaw ChEntrypoint]
  - gmcResolvedComponents :: CacheContents [GmComponent GMCRaw (Set ModulePath)] (Map ChComponentName (GmComponent GMCResolved (Set ModulePath)))
  }
- defaultGhcModState :: GhcModState
- data GmGhcSession = GmGhcSession {
  - gmgsOptions :: ![GHCOption]
  - gmgsSession :: !(IORef HscEnv)
  }
- data GmComponent t eps = GmComponent {
  - gmcHomeModuleGraph :: GmModuleGraph
  - gmcName :: ChComponentName
  - gmcGhcOpts :: [GHCOption]
  - gmcGhcPkgOpts :: [GHCOption]
  - gmcGhcSrcOpts :: [GHCOption]
  - gmcGhcLangOpts :: [GHCOption]
  - gmcRawEntrypoints :: ChEntrypoint
  - gmcEntrypoints :: eps
  - gmcSourceDirs :: [FilePath]
  }
- data GmLogLevel
  - = GmSilent
  - | GmPanic
  - | GmException
  - | GmError
  - | GmWarning
  - | GmInfo
  - | GmDebug
  - | GmVomit
- data GhcModLog = GhcModLog {
  - gmLogLevel :: Maybe GmLogLevel
  - gmLogVomitDump :: Last Bool
  - gmLogMessages :: [(GmLogLevel, String, Doc)]
  }
- data GhcModError
  - = GMENoMsg
  - | GMEString String
  - | GMECabalConfigure GhcModError
  - | GMEStackConfigure GhcModError
  - | GMEStackBootstrap GhcModError
  - | GMECabalCompAssignment [(Either FilePath ModuleName, Set ChComponentName)]
  - | GMEProcess String String [String] (Either Int GhcModError)
  - | GMENoCabalFile
  - | GMETooManyCabalFiles [FilePath]
- type Gm m = (GmEnv m, GmState m, GmLog m, GmOut m)
- class Monad m => GmEnv m where
  - gmeAsk :: m GhcModEnv
  - gmeReader :: (GhcModEnv -> a) -> m a
  - gmeLocal :: (GhcModEnv -> GhcModEnv) -> m a -> m a
- class Monad m => GmState m where
  - gmsGet :: m GhcModState
  - gmsPut :: GhcModState -> m ()
  - gmsState :: (GhcModState -> (a, GhcModState)) -> m a
- class Monad m => GmLog m where
  - gmlJournal :: GhcModLog -> m ()
  - gmlHistory :: m GhcModLog
  - gmlClear :: m ()
- class Monad m => GmOut m where
  - gmoAsk :: m GhcModOut
- cradle :: GmEnv m => m Cradle
- options :: GmEnv m => m Options
- outputOpts :: GmOut m => m OutputOpts
- withOptions :: GmEnv m => (Options -> Options) -> m a -> m a
- getMMappedFiles :: GmState m => m FileMappingMap
- setMMappedFiles :: GmState m => FileMappingMap -> m ()
- addMMappedFile :: GmState m => FilePath -> FileMapping -> m ()
- delMMappedFile :: GmState m => FilePath -> m ()
- lookupMMappedFile :: GmState m => FilePath -> m (Maybe FileMapping)
- getMMappedFilePaths :: GmState m => m [FilePath]
- class MonadIOC m => MonadIO m where
  - liftIO :: IO a -> m a
- gmlGetSession :: (MonadIO m, MonadBaseControl IO m) => GmlT m HscEnv
- gmlSetSession :: (MonadIO m, MonadBaseControl IO m) => HscEnv -> GmlT m ()

# Monad Types

type GhcModT m = GmT (GmOutT m)

newtype GmOutT m a

Constructors

GmOutT |
Fields unGmOutT :: ReaderT GhcModOut m a

Instances

MonadTrans GmOutT |
MonadTransControl GmOutT |
MonadBaseControl IO m => MonadBase IO (GmOutT m) |
MonadBaseControl IO m => MonadBaseControl IO (GmOutT m) |
Monad m => Monad (GmOutT m) |
Functor m => Functor (GmOutT m) |
Applicative m => Applicative (GmOutT m) |
Alternative m => Alternative (GmOutT m) |
MonadPlus m => MonadPlus (GmOutT m) |
GmEnv m => GmEnv (GmOutT m) |
GmLog m => GmLog (GmOutT m) |
Monad m => GmOut (GmOutT m) |
type StT GmOutT a = StT (ReaderT GhcModEnv) a |
type StM (GmOutT m) a = StM (ReaderT GhcModEnv m) a |

newtype GmT m a

Constructors

GmT |
Fields unGmT :: StateT GhcModState (ErrorT GhcModError (JournalT GhcModLog (ReaderT GhcModEnv m))) a

Instances

MonadTrans GmT |
MonadTransControl GmT |
MonadBaseControl IO m => MonadBase IO (GmT m) |
MonadBaseControl IO m => MonadBaseControl IO (GmT m) |
Monad m => MonadJournal GhcModLog (GmT m) |
Monad m => MonadError GhcModError (GmT m) |
MonadReader r m => MonadReader r (GmT m) |
MonadState s m => MonadState s (GmT m) |
Monad m => Monad (GmT m) |
Functor m => Functor (GmT m) |
Monad m => Applicative (GmT m) |
Monad m => Alternative (GmT m) |
Monad m => MonadPlus (GmT m) |
Monad m => GmEnv (GmT m) |
Monad m => GmLog (GmT m) |
GmOut m => GmOut (GmT m) |
Monad m => GmState (GmT m) |
type StT GmT a = (Either GhcModError (a, GhcModState), GhcModLog) |
type StM (GmT m) a = StM (StateT GhcModState (ErrorT GhcModError (JournalT GhcModLog (ReaderT GhcModEnv m)))) a |

newtype GmlT m a

Constructors

GmlT |
Fields unGmlT :: GhcModT m a

Instances

MonadTrans GmlT |
MonadTransControl GmlT |
MonadBaseControl IO m => MonadBase IO (GmlT m) |
MonadBaseControl IO m => MonadBaseControl IO (GmlT m) |
Monad m => MonadError GhcModError (GmlT m) |
Monad m => Monad (GmlT m) |
Functor m => Functor (GmlT m) |
Monad m => Applicative (GmlT m) |
Monad m => Alternative (GmlT m) |
Monad m => MonadPlus (GmlT m) |
(Monad m, GmEnv (GhcModT m)) => GmEnv (GmlT m) |
(Monad m, GmLog (GhcModT m)) => GmLog (GmlT m) |
Monad m => GmOut (GmlT m) |
(Monad m, GmState (GhcModT m)) => GmState (GmlT m) |
type StT GmlT a = StT GmT a |
type StM (GmlT m) a = StM (GmT m) a |

newtype LightGhc a

Constructors

LightGhc |
Fields unLightGhc :: ReaderT (IORef HscEnv) IO a

Instances

Monad LightGhc |
Functor LightGhc |
Applicative LightGhc |

type GmGhc m = (IOish m, GhcMonad m)

type IOish m = (Functor m, MonadIO m, MonadBaseControl IO m, ExceptionMonad m)

A constraint alias (-XConstraintKinds) to make functions dealing with `GhcModT` somewhat cleaner.

Basicially an `IOish m => m` is a `Monad` supporting arbitrary `IO` and exception handling. Usually this will simply be `IO` but we parametrise it in the exported API so users have the option to use a custom inner monad.

# Environment, state and logging

data GhcModEnv

Constructors

GhcModEnv |
Fields gmOptions :: Options gmCradle :: Cradle

data GhcModState

Constructors

GhcModState |
Fields gmGhcSession :: !(Maybe GmGhcSession) gmCaches :: !GhcModCaches gmMMappedFiles :: !FileMappingMap

Instances

Monad m => GmState (StateT GhcModState m) |

data GhcModCaches

Constructors

GhcModCaches |
Fields gmcPackageDbStack :: CacheContents ChCacheData [GhcPkgDb] gmcMergedPkgOptions :: CacheContents ChCacheData [GHCOption] gmcComponents :: CacheContents ChCacheData [GmComponent GMCRaw ChEntrypoint] gmcResolvedComponents :: CacheContents [GmComponent GMCRaw (Set ModulePath)] (Map ChComponentName (GmComponent GMCResolved (Set ModulePath)))

defaultGhcModState :: GhcModState

data GmGhcSession

Constructors

GmGhcSession |
Fields gmgsOptions :: ![GHCOption] gmgsSession :: !(IORef HscEnv)

data GmComponent t eps

Constructors

GmComponent |
Fields gmcHomeModuleGraph :: GmModuleGraph gmcName :: ChComponentName gmcGhcOpts :: [GHCOption] gmcGhcPkgOpts :: [GHCOption] gmcGhcSrcOpts :: [GHCOption] gmcGhcLangOpts :: [GHCOption] gmcRawEntrypoints :: ChEntrypoint gmcEntrypoints :: eps gmcSourceDirs :: [FilePath]

Instances

Functor (GmComponent t) |
Eq eps => Eq (GmComponent t eps) |
Ord eps => Ord (GmComponent t eps) |
Read eps => Read (GmComponent t eps) |
Show eps => Show (GmComponent t eps) |
Generic (GmComponent t eps) |
Binary eps => Binary (GmComponent t eps) |
type Rep (GmComponent t eps) |

# Accessing `GhcModEnv`, `GhcModState` and `GhcModLog`

data GmLogLevel

Constructors

GmSilent |
GmPanic |
GmException |
GmError |
GmWarning |
GmInfo |
GmDebug |
GmVomit |

Instances

Bounded GmLogLevel |
Enum GmLogLevel |
Eq GmLogLevel |
Ord GmLogLevel |
Read GmLogLevel |
Show GmLogLevel |

data GhcModLog

Constructors

GhcModLog |
Fields gmLogLevel :: Maybe GmLogLevel gmLogVomitDump :: Last Bool gmLogMessages :: [(GmLogLevel, String, Doc)]

Instances

Show GhcModLog |
Monoid GhcModLog |
Monad m => MonadJournal GhcModLog (GmT m) |
GmEnv m => GmEnv (JournalT GhcModLog m) |
Monad m => GmLog (JournalT GhcModLog m) |

data GhcModError

Constructors

GMENoMsg | Unknown error
GMEString String | Some Error with a message. These are produced mostly by `fail` calls on GhcModT.
GMECabalConfigure GhcModError | Configuring a cabal project failed.
GMEStackConfigure GhcModError | Configuring a stack project failed.
GMEStackBootstrap GhcModError | Bootstrapping `stack` environment failed (process exited with failure)
GMECabalCompAssignment [(Either FilePath ModuleName, Set ChComponentName)] | Could not find a consistent component assignment for modules
GMEProcess String String [String] (Either Int GhcModError) | Launching an operating system process failed. Fields in order: function, command, arguments, (stdout, stderr, exitcode)
GMENoCabalFile | No cabal file found.
GMETooManyCabalFiles [FilePath] | Too many cabal files found.

Instances

Eq GhcModError |
Show GhcModError |
Exception GhcModError |
Error GhcModError |
Monad m => MonadError GhcModError (GmlT m) |
Monad m => MonadError GhcModError (GmT m) |
GmEnv m => GmEnv (ErrorT GhcModError m) |

type Gm m = (GmEnv m, GmState m, GmLog m, GmOut m)

class Monad m => GmEnv m where

Minimal complete definition

(gmeAsk | gmeReader), gmeLocal

Methods

gmeAsk :: m GhcModEnv

gmeReader :: (GhcModEnv -> a) -> m a

gmeLocal :: (GhcModEnv -> GhcModEnv) -> m a -> m a

Instances

(Monad m, GmEnv (GhcModT m)) => GmEnv (GmlT m) |
Monad m => GmEnv (GmT m) |
GmEnv m => GmEnv (GmOutT m) |
GmEnv m => GmEnv (JournalT GhcModLog m) |
GmEnv m => GmEnv (StateT s m) |
GmEnv m => GmEnv (ErrorT GhcModError m) |

class Monad m => GmState m where

Minimal complete definition

gmsState | gmsGet, gmsPut

Methods

gmsGet :: m GhcModState

gmsPut :: GhcModState -> m ()

gmsState :: (GhcModState -> (a, GhcModState)) -> m a

Instances

GmState m => GmState (MaybeT m) |
(Monad m, GmState (GhcModT m)) => GmState (GmlT m) |
Monad m => GmState (GmT m) |
GmState m => GmState (StateT s m) |
Monad m => GmState (StateT GhcModState m) |

class Monad m => GmLog m where

Methods

gmlJournal :: GhcModLog -> m ()

gmlHistory :: m GhcModLog

gmlClear :: m ()

Instances

(Monad m, GmLog m) => GmLog (MaybeT m) |
(Monad m, GmLog (GhcModT m)) => GmLog (GmlT m) |
Monad m => GmLog (GmT m) |
GmLog m => GmLog (GmOutT m) |
Monad m => GmLog (LogDiscardT m) |
Monad m => GmLog (JournalT GhcModLog m) |
(Monad m, GmLog m) => GmLog (ReaderT r m) |
(Monad m, GmLog m) => GmLog (StateT s m) |
(Monad m, GmLog m, Error e) => GmLog (ErrorT e m) |

class Monad m => GmOut m where

Methods

gmoAsk :: m GhcModOut

Instances

GmOut m => GmOut (MaybeT m) |
Monad m => GmOut (GmlT m) |
GmOut m => GmOut (GmT m) |
Monad m => GmOut (GmOutT m) |
GmOut m => GmOut (JournalT w m) |
GmOut m => GmOut (StateT s m) |

cradle :: GmEnv m => m Cradle

options :: GmEnv m => m Options

outputOpts :: GmOut m => m OutputOpts

withOptions :: GmEnv m => (Options -> Options) -> m a -> m a

getMMappedFiles :: GmState m => m FileMappingMap

setMMappedFiles :: GmState m => FileMappingMap -> m ()

addMMappedFile :: GmState m => FilePath -> FileMapping -> m ()

delMMappedFile :: GmState m => FilePath -> m ()

lookupMMappedFile :: GmState m => FilePath -> m (Maybe FileMapping)

getMMappedFilePaths :: GmState m => m [FilePath]

# Re-exporting convenient stuff

class MonadIOC m => MonadIO m where

Methods

liftIO :: IO a -> m a

gmlGetSession :: (MonadIO m, MonadBaseControl IO m) => GmlT m HscEnv

Get the underlying GHC session

gmlSetSession :: (MonadIO m, MonadBaseControl IO m) => HscEnv -> GmlT m ()

Set the underlying GHC session