@@ -21,10 +21,11 @@ import Ide.Plugin.Eval.Types (Language (Plain), Loc,
21
21
Section (sectionLanguage ),
22
22
Test (.. ), Txt , locate ,
23
23
locate0 )
24
- import InteractiveEval (getContext , parseImportDecl ,
25
- runDecls , setContext )
24
+ import InteractiveEval (execOptions , getContext ,
25
+ parseImportDecl , runDecls ,
26
+ setContext )
26
27
import Language.LSP.Types.Lens (line , start )
27
- import System.IO.Extra (newTempFile , readFile ' )
28
+ import System.IO.Extra (newTempFile , readFileUTF8 ' )
28
29
29
30
-- | Return the ranges of the expression and result parts of the given test
30
31
testRanges :: Test -> (Range , Range )
@@ -95,8 +96,13 @@ evalExtensions =
95
96
evalSetup :: Ghc ()
96
97
evalSetup = do
97
98
preludeAsP <- parseImportDecl " import qualified Prelude as P"
99
+ encodingAsP <- parseImportDecl " import GHC.IO.Encoding as P"
98
100
context <- getContext
99
- setContext (IIDecl preludeAsP : context)
101
+ setContext (IIDecl encodingAsP : IIDecl preludeAsP : context)
102
+ execStmt " P.setLocaleEncoding P.utf8" execOptions >>= \ case
103
+ ExecComplete (Left err) _ -> error $ " failed to set encoding in eval setup: " <> show err
104
+ ExecComplete (Right _) _ -> pure ()
105
+ ExecBreak {} -> error " breakpoints are not supported"
100
106
101
107
-- | A wrapper of 'InteractiveEval.execStmt', capturing the execution result
102
108
myExecStmt :: String -> ExecOptions -> Ghc (Either String (Maybe String ))
@@ -106,7 +112,7 @@ myExecStmt stmt opts = do
106
112
modifySession $ \ hsc -> hsc {hsc_IC = setInteractivePrintName (hsc_IC hsc) evalPrint}
107
113
result <- execStmt stmt opts >>= \ case
108
114
ExecComplete (Left err) _ -> pure $ Left $ show err
109
- ExecComplete (Right _) _ -> liftIO $ Right . (\ x -> if null x then Nothing else Just x) <$> readFile ' temp
115
+ ExecComplete (Right _) _ -> liftIO $ Right . (\ x -> if null x then Nothing else Just x) <$> readFileUTF8 ' temp
110
116
ExecBreak {} -> pure $ Right $ Just " breakpoints are not supported"
111
117
liftIO purge
112
118
pure result
0 commit comments