{-# 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 name :: Located RdrName
name fixity :: LexicalFixity
fixity HsQTvs {..} t :: LHsType GhcPs
t = do
  Text -> R ()
txt "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 -> Bool -> R () -> [R ()] -> R ()
p_infixDefHelper
      (case LexicalFixity
fixity of Infix -> Bool
True; _ -> Bool
False)
      Bool
True
      (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 _ _ (XLHsQTyVars x :: XXLHsQTyVars GhcPs
x) _ = NoExtCon -> R ()
forall a. NoExtCon -> a
noExtCon NoExtCon
XXLHsQTyVars GhcPs
x