{-# 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
import Ormolu.Utils (notImplemented)
import RdrName (RdrName (..))
import SrcLoc (Located)

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 -> (R () -> R ()) -> R () -> [R ()] -> R ()
p_infixDefHelper
      (case LexicalFixity
fixity of Infix -> Bool
True; _ -> 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. Data a => (a -> R ()) -> Located a -> R ()
located' HsTyVarBndr GhcPs -> R ()
p_hsTyVarBndr) [LHsTyVarBndr GhcPs]
hsq_explicit)
  R ()
space
  Text -> R ()
txt "="
  R ()
breakpoint
  R () -> R ()
inci (LHsType GhcPs -> (HsType GhcPs -> R ()) -> R ()
forall a. Data a => Located a -> (a -> R ()) -> R ()
located LHsType GhcPs
t HsType GhcPs -> R ()
p_hsType)
p_synDecl _ _ XLHsQTyVars {} _ = String -> R ()
forall a. String -> a
notImplemented "XLHsQTyVars"