{-# LANGUAGE OverloadedStrings #-}
module HumblePrelude.Plugin (Plugin, importPlugin) where
import HumblePrelude
import GhcPlugins hiding ((<>))
import HsSyn (hsmodImports, simpleImportDecl)
importPlugin :: [String] -> Plugin
importPlugin mods = defaultPlugin
{ parsedResultAction = parsedPlugin . (mods<>)
, pluginRecompile = flagRecompile }
parsedPlugin :: [CommandLineOption] -> ModSummary -> HsParsedModule -> Hsc HsParsedModule
parsedPlugin mods _ pm = do
let rep = noLoc . simpleImportDecl . mkModuleName <$> mods
pure pm { hpm_module = fmap (\m -> m { hsmodImports = rep <> hsmodImports m }) $ hpm_module pm }