{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

-- | Rendering of type synonym declarations.
module Ormolu.Printer.Meat.Declaration.Type
  ( p_synDecl,
  )
where

import GHC.Hs.Extension
import GHC.Hs.Type
import GHC.Parser.Annotation
import GHC.Types.Fixity
import GHC.Types.Name.Reader
import GHC.Types.SrcLoc
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Common
import Ormolu.Printer.Meat.Type

p_synDecl ::
  -- | Type constructor
  LocatedN RdrName ->
  -- | Fixity
  LexicalFixity ->
  -- | Type variables
  LHsQTyVars GhcPs ->
  -- | RHS of type declaration
  LHsType GhcPs ->
  R ()
p_synDecl :: LocatedN RdrName
-> LexicalFixity -> LHsQTyVars GhcPs -> LHsType GhcPs -> R ()
p_synDecl LocatedN RdrName
name LexicalFixity
fixity HsQTvs {[LHsTyVarBndr () GhcPs]
XHsQTvs GhcPs
hsq_ext :: forall pass. LHsQTyVars pass -> XHsQTvs pass
hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
hsq_explicit :: [LHsTyVarBndr () GhcPs]
hsq_ext :: XHsQTvs GhcPs
..} LHsType GhcPs
t = do
  Text -> R ()
txt Text
"type"
  R ()
space
  [SrcSpan] -> R () -> R ()
switchLayout (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LocatedN RdrName
name forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA [LHsTyVarBndr () GhcPs]
hsq_explicit) forall a b. (a -> b) -> a -> b
$
    Bool -> Bool -> R () -> [R ()] -> R ()
p_infixDefHelper
      (case LexicalFixity
fixity of LexicalFixity
Infix -> Bool
True; LexicalFixity
_ -> Bool
False)
      Bool
True
      (LocatedN RdrName -> R ()
p_rdrName LocatedN RdrName
name)
      (forall a b. (a -> b) -> [a] -> [b]
map (forall l a. HasSrcSpan l => (a -> R ()) -> GenLocated l a -> R ()
located' forall flag.
IsInferredTyVarBndr flag =>
HsTyVarBndr flag GhcPs -> R ()
p_hsTyVarBndr) [LHsTyVarBndr () GhcPs]
hsq_explicit)
  R () -> R ()
inci forall a b. (a -> b) -> a -> b
$ do
    R ()
space
    R ()
equals
    if HsType GhcPs -> Bool
hasDocStrings (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
t)
      then R ()
newline
      else R ()
breakpoint
    forall l a. HasSrcSpan l => GenLocated l a -> (a -> R ()) -> R ()
located LHsType GhcPs
t HsType GhcPs -> R ()
p_hsType