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

Use virtual text to show evaluation results #258

Open
leana8959 opened this issue Sep 17, 2023 · 4 comments
Open

Use virtual text to show evaluation results #258

leana8959 opened this issue Sep 17, 2023 · 4 comments
Labels
enhancement New feature or request upstream (hls)

Comments

@leana8959
Copy link

Feature description

Hello,

I noticed that with Scala's metals, the results of an evaluation show up as virtual text; on the other hand, haskell-tools puts them in comments.

Is it possible to have the option to use virtual text instead of comments for evaluation results? I simply think it's neater to not have the file changed when one's simply "probing variables and functions"

A possible problem I can foresee is that longer messages won't fit. A solution could be to place a code action over the evaluated line, which when triggered, shows the complete result.

Here's an image how it looks like for Scala. Note that I can't actually change the text on the right after // because it's virtual text.
image

Thanks, have a nice day :)

@leana8959 leana8959 added the enhancement New feature or request label Sep 17, 2023
@mrcjkb
Copy link
Owner

mrcjkb commented Sep 17, 2023

Hey 😊👋

Thanks for the request.
Unfortunately, I don't think this would be easy to implement in haskell-tools.nvim, as it is haskell-language-server that evaluates the code snippet and adds the result to the document.

I like the idea though. Maybe it could be added to haskell-language-server, in the form of a code action that produces diagnostics or inlay hints or something similar that can be displayed as virtual text.
I fear trying to evaluate code snippets on the fly would be too risky (e.g. what happens if a snippet recurses infinitely?)

I'm not sure, but I think what you're seeing in Scala are inlay hints, not actual code snippet evaluations?

@leana8959
Copy link
Author

leana8959 commented Sep 18, 2023

Unfortunately, I don't think this would be easy to implement in haskell-tools.nvim, as it is haskell-language-server that evaluates the code snippet and adds the result to the document.

I see, maybe I'll create a feature suggestion in their repo :)

I fear trying to evaluate code snippets on the fly would be too risky (e.g. what happens if a snippet recurses infinitely?)

That's also a valid concern that I haven't thought of. In metals it just shows an error diagnostics, and stop evaluating the rest of the code. I think we might need a way to restart the repl if it loops too long.
image

I'm not sure, but I think what you're seeing in Scala are inlay hints, not actual code snippet evaluations?

These are "worksheets", I'm not sure if there is an equivalent of it in Haskell.
Basically, it evaluates the value of each line and shows hints on the right side.
It's a lot more than just type hints.
image

Also thank you for the haskell-tools project, and for taking your time reading my suggestion :)

@mrcjkb
Copy link
Owner

mrcjkb commented Sep 18, 2023

maybe I'll create a feature suggestion in their repo :)

It definitely sounds like a good idea 😄

In metals it just shows an error diagnostics

Haskell doesn't have a recursion limit (it doesn't have a traditional call stack. So the evaluation would probably have to be an async action with a timeout.

Basically, it evaluates the value of each line and shows hints on the right side.
It's a lot more than just type hints.

I could imagine this being very practical for pure evaluations (not in IO).

Also thank you for the haskell-tools project, and for taking your time reading my suggestion :)

No problem. I'm happy to share 😄

@mrcjkb
Copy link
Owner

mrcjkb commented Sep 18, 2023

These are "worksheets", I'm not sure if there is an equivalent of it in Haskell.

Just read through the Scala documentation on worksheets

So if I understand correctly, this is available in files with a special extension, but not regular scala files. Hmm, that could be an interesting feature...

Let's leave this issue open and I'll think about whether it makes sense to contribute it to haskell-language-server. But please feel free to open an issue there. Maybe someone will be faster to implement it than me 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request upstream (hls)
Projects
None yet
Development

No branches or pull requests

2 participants