Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Ormolu
Description
A formatter for Haskell source code.
Synopsis
- ormolu :: MonadIO m => Config RegionIndices -> FilePath -> String -> m Text
- ormoluFile :: MonadIO m => Config RegionIndices -> FilePath -> m Text
- ormoluStdin :: MonadIO m => Config RegionIndices -> m Text
- data Config region = Config {
- cfgDynOptions :: ![DynOption]
- cfgFixityOverrides :: FixityMap
- cfgDependencies :: !(Set String)
- cfgUnsafe :: !Bool
- cfgDebug :: !Bool
- cfgCheckIdempotence :: !Bool
- cfgSourceType :: !SourceType
- cfgColorMode :: !ColorMode
- cfgRegion :: !region
- data ColorMode
- data RegionIndices = RegionIndices {
- regionStartLine :: !(Maybe Int)
- regionEndLine :: !(Maybe Int)
- data SourceType
- defaultConfig :: Config RegionIndices
- detectSourceType :: FilePath -> SourceType
- newtype DynOption = DynOption {
- unDynOption :: String
- data OrmoluException
- = OrmoluParsingFailed SrcSpan String
- | OrmoluOutputParsingFailed SrcSpan String
- | OrmoluASTDiffers TextDiff [RealSrcSpan]
- | OrmoluNonIdempotentOutput TextDiff
- | OrmoluUnrecognizedOpts (NonEmpty String)
- | OrmoluCabalFileParsingFailed FilePath
- | OrmoluMissingStdinInputFile
- | OrmoluFixityOverridesParseError (ParseErrorBundle Text Void)
- withPrettyOrmoluExceptions :: ColorMode -> IO ExitCode -> IO ExitCode
Documentation
Arguments
:: MonadIO m | |
=> Config RegionIndices | Ormolu configuration |
-> FilePath | Location of source file |
-> String | Input to format |
-> m Text |
Format a String
, return formatted version as Text
.
The function
- Takes
String
because that's what GHC parser accepts. - Needs
IO
because some functions from GHC that are necessary to setup parsing context requireIO
. There should be no visible side-effects though. - Takes file name just to use it in parse error messages.
- Throws
OrmoluException
.
NOTE: The caller is responsible for setting the appropriate value in
the cfgSourceType
field. Autodetection of source type won't happen
here, see detectSourceType
.
Arguments
:: MonadIO m | |
=> Config RegionIndices | Ormolu configuration |
-> FilePath | Location of source file |
-> m Text | Resulting rendition |
Load a file and format it. The file stays intact and the rendered
version is returned as Text
.
NOTE: The caller is responsible for setting the appropriate value in
the cfgSourceType
field. Autodetection of source type won't happen
here, see detectSourceType
.
Arguments
:: MonadIO m | |
=> Config RegionIndices | Ormolu configuration |
-> m Text | Resulting rendition |
Read input from stdin and format it.
NOTE: The caller is responsible for setting the appropriate value in
the cfgSourceType
field. Autodetection of source type won't happen
here, see detectSourceType
.
Ormolu configuration.
Constructors
Config | |
Fields
|
Instances
Functor Config Source # | |
Generic (Config region) Source # | |
Show region => Show (Config region) Source # | |
Eq region => Eq (Config region) Source # | |
type Rep (Config region) Source # | |
Defined in Ormolu.Config type Rep (Config region) = D1 ('MetaData "Config" "Ormolu.Config" "ormolu-0.5.0.1-H5rGMumaVxK89QM9QlnNHP" 'False) (C1 ('MetaCons "Config" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cfgDynOptions") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [DynOption]) :*: S1 ('MetaSel ('Just "cfgFixityOverrides") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FixityMap)) :*: (S1 ('MetaSel ('Just "cfgDependencies") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Set String)) :*: S1 ('MetaSel ('Just "cfgUnsafe") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cfgDebug") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: S1 ('MetaSel ('Just "cfgCheckIdempotence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)) :*: (S1 ('MetaSel ('Just "cfgSourceType") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SourceType) :*: (S1 ('MetaSel ('Just "cfgColorMode") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ColorMode) :*: S1 ('MetaSel ('Just "cfgRegion") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 region)))))) |
Whether to use colors and other features of ANSI terminals.
data RegionIndices Source #
Region selection as the combination of start and end line numbers.
Constructors
RegionIndices | |
Fields
|
Instances
Show RegionIndices Source # | |
Defined in Ormolu.Config Methods showsPrec :: Int -> RegionIndices -> ShowS show :: RegionIndices -> String showList :: [RegionIndices] -> ShowS | |
Eq RegionIndices Source # | |
Defined in Ormolu.Config |
data SourceType Source #
Type of sources that can be formatted by Ormolu.
Constructors
ModuleSource | Consider the input as a regular Haskell module |
SignatureSource | Consider the input as a Backpack module signature |
Instances
Show SourceType Source # | |
Defined in Ormolu.Config Methods showsPrec :: Int -> SourceType -> ShowS show :: SourceType -> String showList :: [SourceType] -> ShowS | |
Eq SourceType Source # | |
Defined in Ormolu.Config |
defaultConfig :: Config RegionIndices Source #
Default
.Config
RegionIndices
detectSourceType :: FilePath -> SourceType Source #
Detect SourceType
based on the file extension.
A wrapper for dynamic options.
Constructors
DynOption | |
Fields
|
data OrmoluException Source #
Ormolu exception representing all cases when Ormolu can fail.
Constructors
OrmoluParsingFailed SrcSpan String | Parsing of original source code failed |
OrmoluOutputParsingFailed SrcSpan String | Parsing of formatted source code failed |
OrmoluASTDiffers TextDiff [RealSrcSpan] | Original and resulting ASTs differ |
OrmoluNonIdempotentOutput TextDiff | Formatted source code is not idempotent |
OrmoluUnrecognizedOpts (NonEmpty String) | Some GHC options were not recognized |
OrmoluCabalFileParsingFailed FilePath | Cabal file parsing failed |
OrmoluMissingStdinInputFile | Missing input file path when using stdin input and accounting for .cabal files |
OrmoluFixityOverridesParseError (ParseErrorBundle Text Void) | A parse error in a fixity overrides file |
Instances
Exception OrmoluException Source # | |
Defined in Ormolu.Exception Methods toException :: OrmoluException -> SomeException fromException :: SomeException -> Maybe OrmoluException displayException :: OrmoluException -> String | |
Show OrmoluException Source # | |
Defined in Ormolu.Exception Methods showsPrec :: Int -> OrmoluException -> ShowS show :: OrmoluException -> String showList :: [OrmoluException] -> ShowS | |
Eq OrmoluException Source # | |
Defined in Ormolu.Exception Methods (==) :: OrmoluException -> OrmoluException -> Bool (/=) :: OrmoluException -> OrmoluException -> Bool |
withPrettyOrmoluExceptions Source #
Arguments
:: ColorMode | Color mode |
-> IO ExitCode | Action that may throw an exception |
-> IO ExitCode |
Inside this wrapper OrmoluException
will be caught and displayed
nicely.