Skip to content

Commit 157cd40

Browse files
committed
Fix for Eval plugin: Error from tests not reported
1 parent cbdf0a4 commit 157cd40

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Ide/Plugin/Eval.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ import System.FilePath
8282
import System.IO (hClose)
8383
import System.IO.Temp
8484
import Data.Maybe (catMaybes)
85+
import qualified Control.Exception as E
86+
import Control.DeepSeq ( NFData
87+
, deepseq
88+
)
8589

8690
descriptor :: PluginId -> PluginDescriptor
8791
descriptor plId =
@@ -278,7 +282,12 @@ done, we want to switch back to GhcSessionDeps:
278282
void $ runDecls stmt
279283
return Nothing
280284

281-
edits <- liftIO $ evalGhcEnv hscEnv' $ traverse (eval . first T.unpack) statements
285+
edits <-
286+
liftIO
287+
$ (either (\e -> [Just . T.pack . pad $ e]) id <$>)
288+
$ strictTry
289+
$ evalGhcEnv hscEnv'
290+
$ traverse (eval . first T.unpack) statements
282291

283292

284293
let workspaceEditsMap = Map.fromList [(_uri, List [evalEdit])]
@@ -287,6 +296,11 @@ done, we want to switch back to GhcSessionDeps:
287296

288297
return (WorkspaceApplyEdit, ApplyWorkspaceEditParams workspaceEdits)
289298

299+
strictTry :: NFData b => IO b -> IO (Either String b)
300+
strictTry op = E.catch
301+
(op >>= \v -> return $! Right $! deepseq v v)
302+
(\(err :: E.SomeException) -> return $! Left $ show err)
303+
290304
pad :: String -> String
291305
pad = unlines . map ("-- " <>) . lines
292306

0 commit comments

Comments
 (0)