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

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

import GHC
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Common
import Ormolu.Printer.Meat.Type

p_synDecl ::
  -- | Type constructor
  Located RdrName ->
  -- | Fixity
  LexicalFixity ->
  -- | Type variables
  LHsQTyVars GhcPs ->
  -- | RHS of type declaration
  LHsType GhcPs ->
  R ()
p_synDecl :: Located RdrName
-> LexicalFixity -> LHsQTyVars GhcPs -> LHsType GhcPs -> R ()
p_synDecl Located 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 (Located RdrName -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc Located RdrName
name SrcSpan -> [SrcSpan] -> [SrcSpan]
forall a. a -> [a] -> [a]
: (LHsTyVarBndr GhcPs -> SrcSpan)
-> [LHsTyVarBndr GhcPs] -> [SrcSpan]
forall a b. (a -> b) -> [a] -> [b]
map LHsTyVarBndr GhcPs -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc [LHsTyVarBndr GhcPs]
hsq_explicit) (R () -> R ()) -> R () -> R ()
forall a b. (a -> b) -> a -> b
$
    Bool -> (R () -> R ()) -> R () -> [R ()] -> R ()
p_infixDefHelper
      (case LexicalFixity
fixity of LexicalFixity
Infix -> Bool
True; LexicalFixity
_ -> Bool
False)
      R () -> R ()
inci
      (Located RdrName -> R ()
p_rdrName Located RdrName
name)
      ((LHsTyVarBndr GhcPs -> R ()) -> [LHsTyVarBndr GhcPs] -> [R ()]
forall a b. (a -> b) -> [a] -> [b]
map ((HsTyVarBndr GhcPs -> R ()) -> LHsTyVarBndr GhcPs -> R ()
forall a. (a -> R ()) -> Located a -> R ()
located' HsTyVarBndr GhcPs -> R ()
p_hsTyVarBndr) [LHsTyVarBndr GhcPs]
hsq_explicit)
  R ()
space
  R ()
equals
  if HsType GhcPs -> Bool
hasDocStrings (LHsType GhcPs -> SrcSpanLess (LHsType GhcPs)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsType GhcPs
t)
    then R ()
newline
    else R ()
breakpoint
  R () -> R ()
inci (LHsType GhcPs -> (HsType GhcPs -> R ()) -> R ()
forall a. Located a -> (a -> R ()) -> R ()
located LHsType GhcPs
t HsType GhcPs -> R ()
p_hsType)
p_synDecl Located RdrName
_ LexicalFixity
_ (XLHsQTyVars XXLHsQTyVars GhcPs
x) LHsType GhcPs
_ = NoExtCon -> R ()
forall a. NoExtCon -> a
noExtCon NoExtCon
XXLHsQTyVars GhcPs
x