@@ -12,7 +12,7 @@ import Data.String (IsString)
12
12
import qualified Data.Text as T
13
13
import Development.IDE.Types.Location (Position (.. ), Range (.. ))
14
14
import GHC (ExecOptions , ExecResult (.. ),
15
- execStmt )
15
+ execOptions , execStmt )
16
16
import GHC.LanguageExtensions.Type (Extension (.. ))
17
17
import GhcMonad (Ghc , liftIO , modifySession )
18
18
import HscTypes
@@ -24,7 +24,7 @@ import Ide.Plugin.Eval.Types (Language (Plain), Loc,
24
24
import InteractiveEval (getContext , parseImportDecl ,
25
25
runDecls , setContext )
26
26
import Language.LSP.Types.Lens (line , start )
27
- import System.IO.Extra (newTempFile , readFile ' )
27
+ import System.IO.Extra (newTempFile , readFileUTF8 ' )
28
28
29
29
-- | Return the ranges of the expression and result parts of the given test
30
30
testRanges :: Test -> (Range , Range )
@@ -95,8 +95,13 @@ evalExtensions =
95
95
evalSetup :: Ghc ()
96
96
evalSetup = do
97
97
preludeAsP <- parseImportDecl " import qualified Prelude as P"
98
+ encodingAsP <- parseImportDecl " import GHC.IO.Encoding as P"
98
99
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"
100
105
101
106
-- | A wrapper of 'InteractiveEval.execStmt', capturing the execution result
102
107
myExecStmt :: String -> ExecOptions -> Ghc (Either String (Maybe String ))
@@ -106,7 +111,7 @@ myExecStmt stmt opts = do
106
111
modifySession $ \ hsc -> hsc {hsc_IC = setInteractivePrintName (hsc_IC hsc) evalPrint}
107
112
result <- execStmt stmt opts >>= \ case
108
113
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
110
115
ExecBreak {} -> pure $ Right $ Just " breakpoints are not supported"
111
116
liftIO purge
112
117
pure result
0 commit comments