hie-bios-0.3.0: Set up a GHC API session

Safe HaskellNone
LanguageHaskell2010

HIE.Bios

Contents

Description

The HIE Bios

Provides an abstraction over the GHC Api to initialise a GHC session and loading modules in a project.

Defines the `hie.yaml` file specification. This is used to explicitly configure how a project should be built by GHC.

Synopsis

Find and load a Cradle

data Cradle Source #

The environment of a single Cradle. A Cradle is a unit for the respective build-system.

It contains the root directory of the Cradle, the name of the Cradle (for debugging purposes), and knows how to set up a GHC session that is able to compile files that are part of this Cradle.

A Cradle may be a single unit in the "cabal-install" context, or the whole package, comparable to how "stack" works.

Constructors

Cradle 

Fields

Instances
Show Cradle Source # 
Instance details

Defined in HIE.Bios.Types

data CradleLoadResult r Source #

Result of an attempt to set up a GHC session for a Cradle. This is the go-to error handling mechanism. When possible, this should be preferred over throwing exceptions.

Constructors

CradleSuccess r

The cradle succeeded and returned these options.

CradleFail CradleError

We tried to load the cradle and it failed.

CradleNone

No attempt was made to load the cradle.

Instances
Functor CradleLoadResult Source # 
Instance details

Defined in HIE.Bios.Types

Methods

fmap :: (a -> b) -> CradleLoadResult a -> CradleLoadResult b #

(<$) :: a -> CradleLoadResult b -> CradleLoadResult a #

findCradle :: FilePath -> IO (Maybe FilePath) Source #

Given root/foo/bar.hs, return root/hie.yaml, or wherever the yaml file was found.

loadCradle :: FilePath -> IO Cradle Source #

Given root/hie.yaml load the Cradle.

loadImplicitCradle :: FilePath -> IO Cradle Source #

Given root/foo/bar.hs, load an implicit cradle

defaultCradle :: FilePath -> Cradle Source #

Default cradle has no special options, not very useful for loading modules.

Compiler Options

data ComponentOptions Source #

Option information for GHC

Constructors

ComponentOptions 

Fields

  • componentOptions :: [String]

    Command line options.

  • componentDependencies :: [FilePath]

    Dependencies of a cradle that might change the cradle. Contains both files specified in hie.yaml as well as specified by the build-tool if there is any. FilePaths are expected to be relative to the cradleRootDir to which this CradleAction belongs to. Files returned by this action might not actually exist. This is useful, because, sometimes, adding specific files changes the options that a Cradle may return, thus, needs reload as soon as these files are created.

getCompilerOptions :: FilePath -> Cradle -> IO (CradleLoadResult ComponentOptions) Source #

Initialize the DynFlags relating to the compilation of a single file or GHC session according to the provided Cradle.

Initialising a GHC session from a Cradle

initSession :: GhcMonad m => ComponentOptions -> m [Target] Source #

Start a GHC session and set some sensible options for tooling to use. Creates a folder in the cache directory to cache interface files to make reloading faster.

Loading targets into a GHC session

loadFile Source #

Arguments

:: GhcMonad m 
=> (FilePath, FilePath)

Target file to load.

-> m (Maybe TypecheckedModule, [TypecheckedModule])

Typechecked module and modules that had to be loaded for the target.

Load a target into the GHC session with the default messager which outputs updates in the same format as normal GHC.

The target is represented as a tuple. The tuple consists of the original filename and another file that contains the actual source code to compile.

If the message should configured, use loadFileWithMessage.

If the loading succeeds, the typechecked module is returned together with all the typechecked modules that had to be loaded in order to typecheck the given target.