Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Eval plugin: Error from tests not reported #244

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Ide/Plugin/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ import System.FilePath
import System.IO (hClose)
import System.IO.Temp
import Data.Maybe (catMaybes)
import qualified Control.Exception as E
import Control.DeepSeq ( NFData
, deepseq
)

descriptor :: PluginId -> PluginDescriptor
descriptor plId =
Expand Down Expand Up @@ -278,7 +282,12 @@ done, we want to switch back to GhcSessionDeps:
void $ runDecls stmt
return Nothing

edits <- liftIO $ evalGhcEnv hscEnv' $ traverse (eval . first T.unpack) statements
edits <-
liftIO
$ (either (\e -> [Just . T.pack . pad $ e]) id <$>)
$ strictTry
$ evalGhcEnv hscEnv'
$ traverse (eval . first T.unpack) statements


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

return (WorkspaceApplyEdit, ApplyWorkspaceEditParams workspaceEdits)

strictTry :: NFData b => IO b -> IO (Either String b)
strictTry op = E.catch
(op >>= \v -> return $! Right $! deepseq v v)
(\(err :: E.SomeException) -> return $! Left $ show err)

pad :: String -> String
pad = unlines . map ("-- " <>) . lines

Expand Down