{-# LANGUAGE CPP #-}
-- | Compat module for GHC 9.2 Logger infrastructure.
module Development.IDE.GHC.Compat.Logger (
    putLogHook,
    Logger.pushLogHook,
    -- * Logging stuff
    LogActionCompat,
    logActionCompat,
    defaultLogActionHPutStrDoc,
    ) where

import           Development.IDE.GHC.Compat.Core
import           Development.IDE.GHC.Compat.Env        as Env
import           Development.IDE.GHC.Compat.Outputable


import           GHC.Utils.Logger                      as Logger
import           GHC.Utils.Outputable

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

#if MIN_VERSION_ghc(9,3,0)
import           GHC.Types.Error
#endif

putLogHook :: Logger -> HscEnv -> HscEnv
putLogHook :: Logger -> HscEnv -> HscEnv
putLogHook Logger
logger HscEnv
env =
  HscEnv
env { hsc_logger = logger }

#if MIN_VERSION_ghc(9,3,0)
type LogActionCompat = LogFlags -> Maybe DiagnosticReason -> Maybe Severity -> SrcSpan -> PrintUnqualified -> SDoc -> IO ()

-- alwaysQualify seems to still do the right thing here, according to the "unqualified warnings" test.
logActionCompat :: LogActionCompat -> LogAction
#if MIN_VERSION_ghc(9,7,0)
logActionCompat logAction logFlags (MCDiagnostic severity (ResolvedDiagnosticReason wr) _) loc = logAction logFlags (Just wr) (Just severity) loc alwaysQualify
#elif MIN_VERSION_ghc(9,5,0)
logActionCompat :: LogActionCompat -> LogAction
logActionCompat LogActionCompat
logAction LogFlags
logFlags (MCDiagnostic Severity
severity DiagnosticReason
wr Maybe DiagnosticCode
_) SrcSpan
loc = LogActionCompat
logAction LogFlags
logFlags (DiagnosticReason -> Maybe DiagnosticReason
forall a. a -> Maybe a
Just DiagnosticReason
wr) (Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
severity) SrcSpan
loc NamePprCtx
alwaysQualify
#else
logActionCompat logAction logFlags (MCDiagnostic severity wr) loc = logAction logFlags (Just wr) (Just severity) loc alwaysQualify
#endif
logActionCompat LogActionCompat
logAction LogFlags
logFlags MessageClass
_cls SrcSpan
loc = LogActionCompat
logAction LogFlags
logFlags Maybe DiagnosticReason
forall a. Maybe a
Nothing Maybe Severity
forall a. Maybe a
Nothing SrcSpan
loc NamePprCtx
alwaysQualify

#else
type LogActionCompat = DynFlags -> WarnReason -> Severity -> SrcSpan -> PrintUnqualified -> SDoc -> IO ()

-- alwaysQualify seems to still do the right thing here, according to the "unqualified warnings" test.
logActionCompat :: LogActionCompat -> LogAction
logActionCompat logAction dynFlags wr severity loc = logAction dynFlags wr severity loc alwaysQualify

#endif