{-# LANGUAGE CPP #-}
module Overloaded.Plugin.Diagnostics where

import Control.Monad.IO.Class (MonadIO (..))

import qualified GHC.Compat.All  as GHC
import           GHC.Compat.Expr

-------------------------------------------------------------------------------
-- Doesn't really belong here
-------------------------------------------------------------------------------

#if MIN_VERSION_ghc(9,0,0)
#define ERR_STYLE
#else
#define ERR_STYLE (GHC.defaultErrStyle dflags)
#endif

putError :: MonadIO m => GHC.DynFlags -> SrcSpan -> GHC.SDoc -> m ()
putError :: DynFlags -> SrcSpan -> SDoc -> m ()
putError DynFlags
dflags SrcSpan
l SDoc
doc =
    IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ DynFlags
-> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
GHC.putLogMsg DynFlags
dflags WarnReason
GHC.NoReason Severity
GHC.SevError SrcSpan
l ERR_STYLE doc

warn :: MonadIO m => GHC.DynFlags -> SrcSpan -> GHC.SDoc -> m ()
warn :: DynFlags -> SrcSpan -> SDoc -> m ()
warn DynFlags
dflags SrcSpan
l SDoc
doc =
    IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ DynFlags
-> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
GHC.putLogMsg DynFlags
dflags WarnReason
GHC.NoReason Severity
GHC.SevWarning SrcSpan
l ERR_STYLE doc

debug :: MonadIO m => String -> m ()
-- debug = liftIO . putStrLn
debug :: String -> m ()
debug String
_ = () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()