Language.Haskell.GhcMod.Internal

ghc-mod-5.5.0.0: Happy Haskell Programming

Safe Haskell | None
Language | Haskell2010

Language.Haskell.GhcMod.Internal

Contents

- Types
- Various Paths
- Logging
- Environment, state and logging
- Monad utilities
  - Accessing `GhcModEnv` and `GhcModState`
- `GhcModError`
- World
- Cabal Helper
- Misc stuff
- FileMapping

Description

Low level access to the ghc-mod library.

Synopsis

- type GHCOption = String
- type IncludeDir = FilePath
- newtype GmlT m a = GmlT {
  - unGmlT :: GhcModT m a
  }
- class MonadIOC m => MonadIO m where
  - liftIO :: IO a -> m a
- class Monad m => GmEnv m where
  - gmeAsk :: m GhcModEnv
  - gmeReader :: (GhcModEnv -> a) -> m a
  - gmeLocal :: (GhcModEnv -> GhcModEnv) -> m a -> m a
- ghcLibDir :: FilePath
- ghcModExecutable :: IO FilePath
- withLogger :: (GmGhc m, GmEnv m, GmOut m, GmState m) => (DynFlags -> DynFlags) -> m a -> m (Either String (String, a))
- setNoWarningFlags :: DynFlags -> DynFlags
- setAllWarningFlags :: DynFlags -> DynFlags
- data GhcModEnv = GhcModEnv {
  - gmOptions :: Options
  - gmCradle :: Cradle
  }
- data GhcModState
- data GhcModLog
- class Monad m => GmLog m where
  - gmlJournal :: GhcModLog -> m ()
  - gmlHistory :: m GhcModLog
  - gmlClear :: m ()
- data GmLogLevel
  - = GmSilent
  - | GmPanic
  - | GmException
  - | GmError
  - | GmWarning
  - | GmInfo
  - | GmDebug
  - | GmVomit
- gmSetLogLevel :: GmLog m => GmLogLevel -> m ()
- runGhcModT' :: IOish m => GhcModEnv -> GhcModState -> GhcModT m a -> GmOutT m (Either GhcModError (a, GhcModState), GhcModLog)
- hoistGhcModT :: IOish m => (Either GhcModError a, GhcModLog) -> GhcModT m a
- runGmlT :: IOish m => [Either FilePath ModuleName] -> GmlT m a -> GhcModT m a
- runGmlT' :: IOish m => [Either FilePath ModuleName] -> (DynFlags -> Ghc DynFlags) -> GmlT m a -> GhcModT m a
- gmlGetSession :: (MonadIO m, MonadBaseControl IO m) => GmlT m HscEnv
- gmlSetSession :: (MonadIO m, MonadBaseControl IO m) => HscEnv -> GmlT m ()
- loadTargets :: IOish m => [GHCOption] -> [FilePath] -> GmlT m ()
- cabalResolvedComponents :: IOish m => GhcModT m (Map ChComponentName (GmComponent GMCResolved (Set ModulePath)))
- options :: GmEnv m => m Options
- cradle :: GmEnv m => m Cradle
- targetGhcOptions :: forall m. IOish m => Cradle -> Set (Either FilePath ModuleName) -> GhcModT m [GHCOption]
- withOptions :: GmEnv m => (Options -> Options) -> m a -> m a
- gmeDoc :: GhcModError -> Doc
- data World
- getCurrentWorld :: IOish m => GhcModT m World
- didWorldChange :: IOish m => World -> GhcModT m Bool
- data ModulePath = ModulePath {
  - mpModule :: ModuleName
  - mpPath :: FilePath
  }
- data GmComponent t eps = GmComponent {
  - gmcHomeModuleGraph :: GmModuleGraph
  - gmcName :: ChComponentName
  - gmcGhcOpts :: [GHCOption]
  - gmcGhcPkgOpts :: [GHCOption]
  - gmcGhcSrcOpts :: [GHCOption]
  - gmcGhcLangOpts :: [GHCOption]
  - gmcRawEntrypoints :: ChEntrypoint
  - gmcEntrypoints :: eps
  - gmcSourceDirs :: [FilePath]
  }
- data GmComponentType
  - = GMCRaw
  - | GMCResolved
- data GmModuleGraph = GmModuleGraph {
  - gmgGraph :: Map ModulePath (Set ModulePath)
  }
- prepareCabalHelper :: (IOish m, GmEnv m, GmOut m, GmLog m) => m ()
- data GHandler m a = forall e . Exception e => GHandler (e -> m a)
- gcatches :: (MonadIO m, ExceptionMonad m) => m a -> [GHandler m a] -> m a
- module Language.Haskell.GhcMod.FileMapping

# Types

type GHCOption = String

A single GHC command line option.

type IncludeDir = FilePath

An include directory for modules.

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 |

class MonadIOC m => MonadIO m where

Methods

liftIO :: IO a -> m a

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) |

# Various Paths

ghcLibDir :: FilePath

Obtaining the directory for ghc system libraries.

ghcModExecutable :: IO FilePath

Returns the path to the currently running ghc-mod executable. With ghc<7.6 this is a guess but >=7.6 uses `getExecutablePath`.

# Logging

withLogger :: (GmGhc m, GmEnv m, GmOut m, GmState m) => (DynFlags -> DynFlags) -> m a -> m (Either String (String, a))

Logged messages are returned as `String`. Right is success and Left is failure.

setNoWarningFlags :: DynFlags -> DynFlags

Set `DynFlags` equivalent to "-w:".

setAllWarningFlags :: DynFlags -> DynFlags

Set `DynFlags` equivalent to "-Wall".

# Environment, state and logging

data GhcModEnv

Constructors

GhcModEnv |
Fields gmOptions :: Options gmCradle :: Cradle

data GhcModState

Instances

Monad m => GmState (StateT GhcModState m) |

data GhcModLog

Instances

Show GhcModLog |
Monoid GhcModLog |
Monad m => MonadJournal GhcModLog (GmT m) |
GmEnv m => GmEnv (JournalT GhcModLog m) |
Monad m => GmLog (JournalT GhcModLog 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) |

data GmLogLevel

Constructors

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

Instances

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

gmSetLogLevel :: GmLog m => GmLogLevel -> m ()

# Monad utilities

runGhcModT' :: IOish m => GhcModEnv -> GhcModState -> GhcModT m a -> GmOutT m (Either GhcModError (a, GhcModState), GhcModLog)

Run a computation inside `GhcModT` providing the RWST environment and initial state. This is a low level function, use it only if you know what to do with `GhcModEnv` and `GhcModState`.

You should probably look at `runGhcModT` instead.

hoistGhcModT :: IOish m => (Either GhcModError a, GhcModLog) -> GhcModT m a

`hoistGhcModT result`. Embed a GhcModT computation's result into a GhcModT computation. Note that if the computation that returned `result` modified the state part of GhcModT this cannot be restored.

runGmlT :: IOish m => [Either FilePath ModuleName] -> GmlT m a -> GhcModT m a

Run a GmlT action (i.e. a function in the GhcMonad) in the context of certain files or modules

runGmlT' :: IOish m => [Either FilePath ModuleName] -> (DynFlags -> Ghc DynFlags) -> GmlT m a -> GhcModT m a

Run a GmlT action (i.e. a function in the GhcMonad) in the context of certain files or modules, with updated GHC flags

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

loadTargets :: IOish m => [GHCOption] -> [FilePath] -> GmlT m ()

Set the files as targets and load them.

cabalResolvedComponents :: IOish m => GhcModT m (Map ChComponentName (GmComponent GMCResolved (Set ModulePath)))

## Accessing `GhcModEnv` and `GhcModState`

options :: GmEnv m => m Options

cradle :: GmEnv m => m Cradle

targetGhcOptions :: forall m. IOish m => Cradle -> Set (Either FilePath ModuleName) -> GhcModT m [GHCOption]

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

# `GhcModError`

gmeDoc :: GhcModError -> Doc

# World

data World

Instances

Eq World |

getCurrentWorld :: IOish m => GhcModT m World

didWorldChange :: IOish m => World -> GhcModT m Bool

# Cabal Helper

data ModulePath

Constructors

ModulePath |
Fields mpModule :: ModuleName mpPath :: FilePath

Instances

Eq ModulePath |
Ord ModulePath |
Read ModulePath |
Show ModulePath |
Generic ModulePath |
Binary ModulePath |
type Rep ModulePath |

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) |

data GmComponentType

Constructors

GMCRaw |
GMCResolved |

data GmModuleGraph

Constructors

GmModuleGraph |
Fields gmgGraph :: Map ModulePath (Set ModulePath)

Instances

Eq GmModuleGraph |
Ord GmModuleGraph |
Read GmModuleGraph |
Show GmModuleGraph |
Generic GmModuleGraph |
Binary GmModuleGraph |
Monoid GmModuleGraph |
type Rep GmModuleGraph |

prepareCabalHelper :: (IOish m, GmEnv m, GmOut m, GmLog m) => m ()

# Misc stuff

data GHandler m a

Constructors

forall e . Exception e => GHandler (e -> m a) |

gcatches :: (MonadIO m, ExceptionMonad m) => m a -> [GHandler m a] -> m a

# FileMapping

module Language.Haskell.GhcMod.FileMapping