Skip to content

Eval plugin: evaluate expressions as statements#1603

Merged
berberman merged 4 commits into
haskell:masterfrom
berberman:eval-it
Mar 22, 2021
Merged

Eval plugin: evaluate expressions as statements#1603
berberman merged 4 commits into
haskell:masterfrom
berberman:eval-it

Conversation

@berberman

Copy link
Copy Markdown
Collaborator

Closes #1577

#438 introduced an alternative way to evaluate expressions: we wrapped expressions with asPrint, and then used compileExpr to get the coerced result IO String. However, it broke functionality of it variable -- referencing the last evaluated result.

This PR restores the old eval plugin's behaviour: there is no special treatment for expressions anymore; instead, expressions are just statements, and we redirect the output of execStmt to a temporary file to get the same result as compileExpr.

@pepeiborra pepeiborra left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Comment thread plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Code.hs Outdated
@berberman

Copy link
Copy Markdown
Collaborator Author

All test cases on Windows are failing:

lexical error in string/character literal at character 'U'

Perhaps an encoding-related issue?

@jneira

jneira commented Mar 22, 2021

Copy link
Copy Markdown
Member

@berberman mmm, i think you will have to save the file using utf-8, not sure how being in a evaluated expression, see

let writeFileUTF8NoNewLineTranslation file txt =
withFile file WriteMode $ \h -> do
hSetEncoding h utf8
hSetNewlineMode h noNewlineTranslation
hPutStr h (T.unpack txt)

(maybe you will not need the newline thing)

There is a function in the extra package writeUtf8 but i guess maybe you cant use it in that context.

@berberman

Copy link
Copy Markdown
Collaborator Author

Never mind, I found it might be caused by the backslash was not escaped properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline eval no longer capable of using "it" to reference the output of the previous inline

3 participants