Skip to content

Evaluate file #451

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

Closed
dustinlacewell opened this issue Sep 3, 2021 · 4 comments
Closed

Evaluate file #451

dustinlacewell opened this issue Sep 3, 2021 · 4 comments
Labels
type: question Questions about anything

Comments

@dustinlacewell
Copy link

I was surprised to find there is no feature for just evaluating the current file. Would that be a useful feature? I am just learning Haskell and I think it could be. Maybe I missed it.

@jneira
Copy link
Member

jneira commented Sep 3, 2021

Hi, welcome to haskell and thanks to open the issue, could you elaborate what do you mean with "evaluate the current file"? opening it in a repl/ghci session?
The ide now loads the file with ghc and provide lot of info as diagnostics. Otoh you have available the eval plugin to evaluate expressions in the module context:

Eval

@jneira jneira added the type: question Questions about anything label Sep 3, 2021
@dustinlacewell
Copy link
Author

Right, I knew that you could evaluate code within comments. But why not the whole file? Why not just throw a bit of code into a file and evaluate it it (output in the vscode output pane)? I guess I'm confused why it is limited to just within comments of a file.

@konn
Copy link
Contributor

konn commented Sep 5, 2021

It seems you have some misconceptions about Haskell modules. Every Haskell program file is a mere module.
Haskell modules consist solely of declarations of functions or types - hence, in Haskell, "evaluating whole the Module" doesn't make sense, as opposed to scripting languages such as Ruby or Python.

Or, perhaps you might want execute the Main module. In Haskell, the module is marked as main module and provides main function, then Haskell treats it as the entry point of the program, as in C or Rust. If you want to simulate this behaviour, you can just invoke main function in Eval comment or REPL prompt.

And indeed, Eval Plugin (eval-in-comment feature as described above by @jneria) loads an entire module and evaluate the expression in that context. This is essentially the same as loading modules within GHCi (interactive REPL) and evaluating code fragments in the prompt.

Indeed, there has long been a plan to support a feature to open REPL process using Language Server's context as a separate process - see haskell/haskell-language-server#477 and #450.
Meanwhile, you can use either Eval-in-comment, or open a separate terminal in VSCode and invoke ghci manually to load the modules in REPL. Note that the latter approach doesn't share the internal state with Language Server, so it can have stale state compared to the Language Server and you have to reload module manually. Or, perhaps you could simultaneously use ghcide in addition to HLS, which saves manual reloads.

@dustinlacewell
Copy link
Author

Or, perhaps you might want execute the Main module.

Yeah that. Invoking main from a comment is not bad at all I'll do that. Thank you for the detailed response, I appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about anything
Projects
None yet
Development

No branches or pull requests

3 participants