@@ -12,7 +12,7 @@ import Data.String (IsString)
1212import qualified Data.Text as T
1313import Development.IDE.Types.Location (Position (.. ), Range (.. ))
1414import GHC (ExecOptions , ExecResult (.. ),
15- execStmt )
15+ execOptions , execStmt )
1616import GHC.LanguageExtensions.Type (Extension (.. ))
1717import GhcMonad (Ghc , liftIO , modifySession )
1818import HscTypes
@@ -24,7 +24,7 @@ import Ide.Plugin.Eval.Types (Language (Plain), Loc,
2424import InteractiveEval (getContext , parseImportDecl ,
2525 runDecls , setContext )
2626import Language.LSP.Types.Lens (line , start )
27- import System.IO.Extra (newTempFile , readFile ' )
27+ import System.IO.Extra (newTempFile , readFileUTF8 ' )
2828
2929-- | Return the ranges of the expression and result parts of the given test
3030testRanges :: Test -> (Range , Range )
@@ -95,8 +95,13 @@ evalExtensions =
9595evalSetup :: Ghc ()
9696evalSetup = do
9797 preludeAsP <- parseImportDecl " import qualified Prelude as P"
98+ encodingAsP <- parseImportDecl " import GHC.IO.Encoding as P"
9899 context <- getContext
99- setContext (IIDecl preludeAsP : context)
100+ setContext (IIDecl encodingAsP : IIDecl preludeAsP : context)
101+ execStmt " setLocaleEncoding utf8" execOptions >>= \ case
102+ ExecComplete (Left err) _ -> error $ " failed to set encoding in eval setup: " <> show err
103+ ExecComplete (Right _) _ -> pure ()
104+ ExecBreak {} -> error " breakpoints are not supported"
100105
101106-- | A wrapper of 'InteractiveEval.execStmt', capturing the execution result
102107myExecStmt :: String -> ExecOptions -> Ghc (Either String (Maybe String ))
@@ -106,7 +111,7 @@ myExecStmt stmt opts = do
106111 modifySession $ \ hsc -> hsc {hsc_IC = setInteractivePrintName (hsc_IC hsc) evalPrint}
107112 result <- execStmt stmt opts >>= \ case
108113 ExecComplete (Left err) _ -> pure $ Left $ show err
109- ExecComplete (Right _) _ -> liftIO $ Right . (\ x -> if null x then Nothing else Just x ) <$> readFile ' temp
114+ ExecComplete (Right _) _ -> liftIO $ Right . (\ x -> if null x then Nothing else Just x) <$> readFileUTF8 ' temp
110115 ExecBreak {} -> pure $ Right $ Just " breakpoints are not supported"
111116 liftIO purge
112117 pure result
0 commit comments