diff options
author | MorrowM <themorrowm@gmail.com> | 2022-08-14 23:17:55 +0300 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-08-21 16:51:38 -0400 |
commit | 9939e95fb7b808b68aca00dfabbb99079927f482 (patch) | |
tree | 25866e9a6a17c818dd64d132fb534682a246ef39 /ghc | |
parent | ab3e0f5a02f6a1b63407e08bb97a228a76c27abd (diff) | |
download | haskell-9939e95fb7b808b68aca00dfabbb99079927f482.tar.gz |
Recognize file-header pragmas in GHCi (#21507)
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/GHCi/UI.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index b19939e9ac..4eb9cd9324 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -78,6 +78,7 @@ import GHC.Types.Name.Reader as RdrName ( getGRE_NameQualifier_maybes, getRdrNam import GHC.Types.SrcLoc as SrcLoc import qualified GHC.Parser.Lexer as Lexer import GHC.Parser.Header ( toArgs ) +import qualified GHC.Parser.Header as Header import GHC.Types.PkgQual import GHC.Unit @@ -1249,6 +1250,9 @@ runStmt input step = do let source = progname st let line = line_number st + -- Add any LANGUAGE/OPTIONS_GHC pragmas we find find. + set_pragmas pflags + if | GHC.isStmt pflags input -> do hsc_env <- GHC.getSession mb_stmt <- liftIO (runInteractiveHsc hsc_env (hscParseStmtWithLocation source line input)) @@ -1282,6 +1286,12 @@ runStmt input step = do run_imports imports = mapM_ (addImportToContext . unLoc) imports + set_pragmas pflags = + let stringbuf = stringToStringBuffer input + (_msgs, loc_opts) = Header.getOptions pflags stringbuf "<interactive>" + opts = unLoc <$> loc_opts + in setOptions opts + run_stmt :: GhciMonad m => GhciLStmt GhcPs -> m (Maybe GHC.ExecResult) run_stmt stmt = do m_result <- GhciMonad.runStmt stmt input step |