{- |
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
        { CompatGHC.generalFlags =
            CompatGHC.insertEnumSet CompatGHC.Opt_Haddock (CompatGHC.generalFlags 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
        { CompatGHC.hsc_dflags = newDflags
        }