{- |
Module: Pollock.DriverPlugin
Copyright: (c) Trevis Elser 2023
License: MIT
Maintainer: trevis@flipstone.com
Stability: experimental
-}
module Pollock.DriverPlugin
  ( ensureHaddockIsOn
  ) where

import qualified Pollock.CompatGHC as CompatGHC

{- | A helper suitable for use to set as 'driverPlugin' that ensures the Haddock option is set to
allow other funcationality provided here to work.
-}
ensureHaddockIsOn :: [a] -> CompatGHC.HscEnv -> IO CompatGHC.HscEnv
ensureHaddockIsOn :: forall a. [a] -> HscEnv -> IO HscEnv
ensureHaddockIsOn [a]
_ HscEnv
env =
  let
    dflags :: DynFlags
dflags = HscEnv -> DynFlags
CompatGHC.hsc_dflags HscEnv
env
    newDflags :: DynFlags
newDflags =
      DynFlags
dflags
        { generalFlags :: EnumSet GeneralFlag
CompatGHC.generalFlags =
            GeneralFlag -> EnumSet GeneralFlag -> EnumSet GeneralFlag
forall a. Enum a => a -> EnumSet a -> EnumSet a
CompatGHC.insertEnumSet GeneralFlag
CompatGHC.Opt_Haddock (DynFlags -> EnumSet GeneralFlag
CompatGHC.generalFlags DynFlags
dflags)
        }
   in
    HscEnv -> IO HscEnv
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HscEnv -> IO HscEnv) -> HscEnv -> IO HscEnv
forall a b. (a -> b) -> a -> b
$
      HscEnv
env
        { hsc_dflags :: DynFlags
CompatGHC.hsc_dflags = DynFlags
newDflags
        }