haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.61k stars 351 forks source link

MetaLS-like virtual text evaluation instead of comments #4246

Open leana8959 opened 1 month ago

leana8959 commented 1 month ago

Is your enhancement request related to a problem? Please describe.

I find the choice of having evaluation (-- >>>) result as comments suboptimal, since I would like the result to be only shown to the reader of the code and not be a textual part of the document. This is not a blocker, but it can be better.

Describe the solution you'd like

Scala's MetaLS[^1] supports a special file type: "worksheets". For this kind of files, every expression is evaluated on-the-fly and the value of that line is shown as virtual text on the side.

image

It is worth considering evaluating each (pure) expression and have their value on the right-hand side. It can be an interesting feature, documenting examples for beginners. However, the focus of my suggestion remains on using virtual text over comments.

I have previously opened an issue here mrcjkb/haskell-tools.nvim#258

Describe alternatives you've considered

ghci, but it's nowhere as immersive and intuitive as having inline evaluation on the fly.

Additional context

Maybe long lines will be truncated (at least, I do not know how to avoid it). I might do some research on this when I have free time.

Thank you for the project and for reading my suggestion :)

[^1]: Meta Language Server

michaelpj commented 1 month ago

I think the best way to do this would be via proper notebook support. It looks like there may be something like this in the next 3.18 version of the LSP spec. So ideally we would just hook into the notebook support. That would be a big task, though.

However, I guess we possibly could provide an explicitly triggered version of this using inlay hints? Something like:

x :: Int
x = 1 + 2 // eval: <hint>3</hint>

Might be kind of expensive to keep computing, not sure.