    {-# LANGUAGE DeriveFunctor #-}
    {-# LANGUAGE RecordWildCards #-}

    -- | Configuration options used by the tool.
    module Ormolu.Config
      ( Config (..),
        RegionIndices (..),
        RegionDeltas (..),
        defaultConfig,
        regionIndicesToDeltas,
        DynOption (..),
        dynOptionToLocatedStr,
      )
    where

    import qualified SrcLoc as GHC

    -- | Ormolu configuration.
    data Config region = Config
      { -- | Dynamic options to pass to GHC parser
        Config region -> [DynOption]
    cfgDynOptions :: ![DynOption],
        -- | Do formatting faster but without automatic detection of defects
        Config region -> Bool
    cfgUnsafe :: !Bool,
        -- | Output information useful for debugging
        Config region -> Bool
    cfgDebug :: !Bool,
        -- | Checks if re-formatting the result is idempotent
        Config region -> Bool
    cfgCheckIdempotence :: !Bool,
        -- | Region selection
        Config region -> region
    cfgRegion :: !region
      }
      deriving (Config region -> Config region -> Bool
    (Config region -> Config region -> Bool)
    -> (Config region -> Config region -> Bool) -> Eq (Config region)
    forall region. Eq region => Config region -> Config region -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Config region -> Config region -> Bool
    $c/= :: forall region. Eq region => Config region -> Config region -> Bool
    == :: Config region -> Config region -> Bool
    $c== :: forall region. Eq region => Config region -> Config region -> Bool
    Eq, Int -> Config region -> ShowS
    [Config region] -> ShowS
    Config region -> String
    (Int -> Config region -> ShowS)
    -> (Config region -> String)
    -> ([Config region] -> ShowS)
    -> Show (Config region)
    forall region. Show region => Int -> Config region -> ShowS
    forall region. Show region => [Config region] -> ShowS
    forall region. Show region => Config region -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [Config region] -> ShowS
    $cshowList :: forall region. Show region => [Config region] -> ShowS
    show :: Config region -> String
    $cshow :: forall region. Show region => Config region -> String
    showsPrec :: Int -> Config region -> ShowS
    $cshowsPrec :: forall region. Show region => Int -> Config region -> ShowS
    Show, a -> Config b -> Config a
    (a -> b) -> Config a -> Config b
    (forall a b. (a -> b) -> Config a -> Config b)
    -> (forall a b. a -> Config b -> Config a) -> Functor Config
    forall a b. a -> Config b -> Config a
    forall a b. (a -> b) -> Config a -> Config b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    <$ :: a -> Config b -> Config a
    $c<$ :: forall a b. a -> Config b -> Config a
    fmap :: (a -> b) -> Config a -> Config b
    $cfmap :: forall a b. (a -> b) -> Config a -> Config b
    Functor)

    -- | Region selection as the combination of start and end line numbers.
    data RegionIndices = RegionIndices
      { -- | Start line of the region to format
        RegionIndices -> Maybe Int
    regionStartLine :: !(Maybe Int),
        -- | End line of the region to format
        RegionIndices -> Maybe Int
    regionEndLine :: !(Maybe Int)
      }
      deriving (RegionIndices -> RegionIndices -> Bool
    (RegionIndices -> RegionIndices -> Bool)
    -> (RegionIndices -> RegionIndices -> Bool) -> Eq RegionIndices
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: RegionIndices -> RegionIndices -> Bool
    $c/= :: RegionIndices -> RegionIndices -> Bool
    == :: RegionIndices -> RegionIndices -> Bool
    $c== :: RegionIndices -> RegionIndices -> Bool
    Eq, Int -> RegionIndices -> ShowS
    [RegionIndices] -> ShowS
    RegionIndices -> String
    (Int -> RegionIndices -> ShowS)
    -> (RegionIndices -> String)
    -> ([RegionIndices] -> ShowS)
    -> Show RegionIndices
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [RegionIndices] -> ShowS
    $cshowList :: [RegionIndices] -> ShowS
    show :: RegionIndices -> String
    $cshow :: RegionIndices -> String
    showsPrec :: Int -> RegionIndices -> ShowS
    $cshowsPrec :: Int -> RegionIndices -> ShowS
    Show)

    -- | Region selection as the length of the literal prefix and the literal
    -- suffix.
    data RegionDeltas = RegionDeltas
      { -- | Prefix length in number of lines
        RegionDeltas -> Int
    regionPrefixLength :: !Int,
        -- | Suffix length in number of lines
        RegionDeltas -> Int
    regionSuffixLength :: !Int
      }
      deriving (RegionDeltas -> RegionDeltas -> Bool
    (RegionDeltas -> RegionDeltas -> Bool)
    -> (RegionDeltas -> RegionDeltas -> Bool) -> Eq RegionDeltas
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: RegionDeltas -> RegionDeltas -> Bool
    $c/= :: RegionDeltas -> RegionDeltas -> Bool
    == :: RegionDeltas -> RegionDeltas -> Bool
    $c== :: RegionDeltas -> RegionDeltas -> Bool
    Eq, Int -> RegionDeltas -> ShowS
    [RegionDeltas] -> ShowS
    RegionDeltas -> String
    (Int -> RegionDeltas -> ShowS)
    -> (RegionDeltas -> String)
    -> ([RegionDeltas] -> ShowS)
    -> Show RegionDeltas
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [RegionDeltas] -> ShowS
    $cshowList :: [RegionDeltas] -> ShowS
    show :: RegionDeltas -> String
    $cshow :: RegionDeltas -> String
    showsPrec :: Int -> RegionDeltas -> ShowS
    $cshowsPrec :: Int -> RegionDeltas -> ShowS
    Show)

    -- | Default @'Config' 'RegionIndices'@.
    defaultConfig :: Config RegionIndices
    defaultConfig :: Config RegionIndices
    defaultConfig =
      $WConfig :: forall region.
    [DynOption] -> Bool -> Bool -> Bool -> region -> Config region
    Config
        { cfgDynOptions :: [DynOption]
    cfgDynOptions = [],
          cfgUnsafe :: Bool
    cfgUnsafe = Bool
    False,
          cfgDebug :: Bool
    cfgDebug = Bool
    False,
          cfgCheckIdempotence :: Bool
    cfgCheckIdempotence = Bool
    False,
          cfgRegion :: RegionIndices
    cfgRegion =
            $WRegionIndices :: Maybe Int -> Maybe Int -> RegionIndices
    RegionIndices
              { regionStartLine :: Maybe Int
    regionStartLine = Maybe Int
    forall a. Maybe a
    Nothing,
                regionEndLine :: Maybe Int
    regionEndLine = Maybe Int
    forall a. Maybe a
    Nothing
              }
        }

    -- | Convert 'RegionIndices' into 'RegionDeltas'.
    regionIndicesToDeltas ::
      -- | Total number of lines in the input
      Int ->
      -- | Region indices
      RegionIndices ->
      -- | Region deltas
      RegionDeltas
    regionIndicesToDeltas :: Int -> RegionIndices -> RegionDeltas
    regionIndicesToDeltas total :: Int
    total RegionIndices {..} =
      $WRegionDeltas :: Int -> Int -> RegionDeltas
    RegionDeltas
        { regionPrefixLength :: Int
    regionPrefixLength = Int -> (Int -> Int) -> Maybe Int -> Int
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe 0 (Int -> Int -> Int
    forall a. Num a => a -> a -> a
    subtract 1) Maybe Int
    regionStartLine,
          regionSuffixLength :: Int
    regionSuffixLength = Int -> (Int -> Int) -> Maybe Int -> Int
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe 0 (Int
    total Int -> Int -> Int
    forall a. Num a => a -> a -> a
    -) Maybe Int
    regionEndLine
        }

    -- | A wrapper for dynamic options.
    newtype DynOption = DynOption
      { DynOption -> String
    unDynOption :: String
      }
      deriving (DynOption -> DynOption -> Bool
    (DynOption -> DynOption -> Bool)
    -> (DynOption -> DynOption -> Bool) -> Eq DynOption
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: DynOption -> DynOption -> Bool
    $c/= :: DynOption -> DynOption -> Bool
    == :: DynOption -> DynOption -> Bool
    $c== :: DynOption -> DynOption -> Bool
    Eq, Eq DynOption
    Eq DynOption =>
    (DynOption -> DynOption -> Ordering)
    -> (DynOption -> DynOption -> Bool)
    -> (DynOption -> DynOption -> Bool)
    -> (DynOption -> DynOption -> Bool)
    -> (DynOption -> DynOption -> Bool)
    -> (DynOption -> DynOption -> DynOption)
    -> (DynOption -> DynOption -> DynOption)
    -> Ord DynOption
    DynOption -> DynOption -> Bool
    DynOption -> DynOption -> Ordering
    DynOption -> DynOption -> DynOption
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    min :: DynOption -> DynOption -> DynOption
    $cmin :: DynOption -> DynOption -> DynOption
    max :: DynOption -> DynOption -> DynOption
    $cmax :: DynOption -> DynOption -> DynOption
    >= :: DynOption -> DynOption -> Bool
    $c>= :: DynOption -> DynOption -> Bool
    > :: DynOption -> DynOption -> Bool
    $c> :: DynOption -> DynOption -> Bool
    <= :: DynOption -> DynOption -> Bool
    $c<= :: DynOption -> DynOption -> Bool
    < :: DynOption -> DynOption -> Bool
    $c< :: DynOption -> DynOption -> Bool
    compare :: DynOption -> DynOption -> Ordering
    $ccompare :: DynOption -> DynOption -> Ordering
    $cp1Ord :: Eq DynOption
    Ord, Int -> DynOption -> ShowS
    [DynOption] -> ShowS
    DynOption -> String
    (Int -> DynOption -> ShowS)
    -> (DynOption -> String)
    -> ([DynOption] -> ShowS)
    -> Show DynOption
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [DynOption] -> ShowS
    $cshowList :: [DynOption] -> ShowS
    show :: DynOption -> String
    $cshow :: DynOption -> String
    showsPrec :: Int -> DynOption -> ShowS
    $cshowsPrec :: Int -> DynOption -> ShowS
    Show)

    -- | Convert 'DynOption' to @'GHC.Located' 'String'@.
    dynOptionToLocatedStr :: DynOption -> GHC.Located String
    dynOptionToLocatedStr :: DynOption -> Located String
    dynOptionToLocatedStr (DynOption o :: String
    o) = SrcSpan -> String -> Located String
    forall l e. l -> e -> GenLocated l e
    GHC.L SrcSpan
    GHC.noSrcSpan String
    o