Skip to content

Commit

Permalink
Only run plugin on modules that have bangs
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
JakobBruenker committed May 20, 2024
1 parent b1171e7 commit 152d8ef
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/MonadicBang/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,22 @@ spanToLoc :: RealSrcSpan -> Loc
spanToLoc = liftA2 MkLoc srcLocLine srcLocCol . realSrcSpanStart

replaceBangs :: [CommandLineOption] -> ModSummary -> Handler Hsc ParsedResult
replaceBangs cmdLineOpts _ (ParsedResult (HsParsedModule mod' files) msgs) = do
options <- liftIO . (either throwIO pure =<<) . runThrow @ErrorCall $ parseOptions mod' cmdLineOpts
dflags <- getDynFlags
(newErrors, mod'') <-
runM .
runUniquesIO 'p' .
runWriter .
runReader options .
runReader noneInScope .
evalWriter @Occs .
runReader dflags $
fillHoles fills mod'
log options.verbosity (ppr mod'')
pure $ ParsedResult (HsParsedModule mod'' files) msgs{psErrors = oldErrors <> newErrors}
replaceBangs cmdLineOpts _ orig@(ParsedResult (HsParsedModule mod' files) msgs)
| null fills = pure orig
| otherwise = do
options <- liftIO . (either throwIO pure =<<) . runThrow @ErrorCall $ parseOptions mod' cmdLineOpts
dflags <- getDynFlags
(newErrors, mod'') <-
runM .
runUniquesIO 'p' .
runWriter .
runReader options .
runReader noneInScope .
evalWriter @Occs .
runReader dflags $
fillHoles fills mod'
log options.verbosity (ppr mod'')
pure $ ParsedResult (HsParsedModule mod'' files) msgs{psErrors = oldErrors <> newErrors}
where
log = \cases
Quiet _ -> pure ()
Expand Down

0 comments on commit 152d8ef

Please sign in to comment.