{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RecordWildCards #-}
module Ormolu.Config
( Config (..),
RegionIndices (..),
RegionDeltas (..),
defaultConfig,
regionIndicesToDeltas,
DynOption (..),
dynOptionToLocatedStr,
)
where
import qualified SrcLoc as GHC
data Config region = Config
{
cfgDynOptions :: ![DynOption],
cfgUnsafe :: !Bool,
cfgDebug :: !Bool,
cfgCheckIdempotence :: !Bool,
cfgRegion :: !region
}
deriving (Eq, Show, Functor)
data RegionIndices = RegionIndices
{
regionStartLine :: !(Maybe Int),
regionEndLine :: !(Maybe Int)
}
deriving (Eq, Show)
data RegionDeltas = RegionDeltas
{
regionPrefixLength :: !Int,
regionSuffixLength :: !Int
}
deriving (Eq, Show)
defaultConfig :: Config RegionIndices
defaultConfig =
Config
{ cfgDynOptions = [],
cfgUnsafe = False,
cfgDebug = False,
cfgCheckIdempotence = False,
cfgRegion =
RegionIndices
{ regionStartLine = Nothing,
regionEndLine = Nothing
}
}
regionIndicesToDeltas ::
Int ->
RegionIndices ->
RegionDeltas
regionIndicesToDeltas total RegionIndices {..} =
RegionDeltas
{ regionPrefixLength = maybe 0 (subtract 1) regionStartLine,
regionSuffixLength = maybe 0 (total -) regionEndLine
}
newtype DynOption = DynOption
{ unDynOption :: String
}
deriving (Eq, Ord, Show)
dynOptionToLocatedStr :: DynOption -> GHC.Located String
dynOptionToLocatedStr (DynOption o) = GHC.L GHC.noSrcSpan o