Skip to content

Comments

Evaluate Shell-Style Comments using the LSP#2360

Draft
Hyalunar wants to merge 20 commits intodiku-dk:masterfrom
Hyalunar:lsp-eval-comment
Draft

Evaluate Shell-Style Comments using the LSP#2360
Hyalunar wants to merge 20 commits intodiku-dk:masterfrom
Hyalunar:lsp-eval-comment

Conversation

@Hyalunar
Copy link
Contributor

@Hyalunar Hyalunar commented Feb 1, 2026

Closes #2358

This is currently in this state:

  • you must make your editor request the code lenses yourself
  • you can trigger the code lens, it will verify the parameters
  • if everything goes well, the lsp will crash
  • evaluating the expression is not implemented yet

I would like to reuse some code from futhark eval, but I'm not sure how to do it, since futhark eval has no underlying support module and does not export anything except for main. I could call main, but it would write to stdout, which is inacceptable in this scenario.

@athas
Copy link
Member

athas commented Feb 1, 2026

Perhaps you could move some of the logic from Futhark.CLI.Eval to a new module Futhark.Eval? Setting up the interpreter is somewhat intricate, and there is no reason to duplicate that logic.

@athas
Copy link
Member

athas commented Feb 1, 2026

What happens if the user evaluates an infinite loop, or something that uses up all your memory?

@Hyalunar
Copy link
Contributor Author

Hyalunar commented Feb 1, 2026

What happens if the user evaluates an infinite loop, or something that uses up all your memory?

It loops infinitely many times or uses up all the memory. Feels like a halting problem to me. We could do some best-effort stuff like a memory or execution time limit.

@Hyalunar
Copy link
Contributor Author

Hyalunar commented Feb 1, 2026

It loops infinitely many times or uses up all the memory. Feels like a halting problem to me. We could do some best-effort stuff like a memory or execution time limit.

HLS has exactly the same problem, they don't have any guardrails and it has forced me to kill the Language Server at least a few times.

Usually, implementing a time and memory limit should be hard but I think asynchronous exceptions and heap allocation limits could work like a charm here.

Leavingy the questions: what is a reasonable limit? What if the user hits it but wants to continue?

@athas
Copy link
Member

athas commented Feb 1, 2026

This is a good argument for doing the evaluation in a separate process.

@Hyalunar
Copy link
Contributor Author

Hyalunar commented Feb 11, 2026

My work on this has stalled a little bit because I'm struggling to figure out how to properly set up the interpreter.
It seems like futhark eval is set on reading the files from disk, which would need to be factored out because the LSP might have newer/better code than whatever is on disk (The code that is in the file might not even compile, but the LSP always has a last known good state).

@athas
Copy link
Member

athas commented Feb 11, 2026

The interpreter goes through the infrastructure in Futhark.Compiler.Program, which supports a VFS structure for overriding disk contents.

@Hyalunar
Copy link
Contributor Author

The basic support is there, just not very fleshed out yet.
asciicast

@athas
Copy link
Member

athas commented Feb 19, 2026

Cool!

@vox9, this might also be a useful application for your work.

@Hyalunar
Copy link
Contributor Author

Hyalunar commented Feb 22, 2026

The feature works as intended now. I would appreciate feedback on some improvements/design decisions I have in mind.

Timeout

Currently, the evaluation is limited using a memory limit on total allocations, this is documented to be portable.
Additionally, a timeout could be implemented using asynchronous exceptions but this seems to be GHC-Specific. Would this be a problem?
Also, the Language Server is Unresponsive while the evaluation is running. I have not yet found out how to circumvent this.

Trace

When the evaluation times out, all the traces are thrown away. It's possible to retain and display them, but they might be huge (since the computation timed out), maybe it's better not to?

Hitting the Limits

There is no way to use the feature when your expression times out. I'm open for ideas on how this could be avoided.

  • configuration, but from where?
  • re-running with increased limits (where could the required information be stored reliably?)
  • disabling the limit for a single run with a special directive

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.

Evaluate Shell-Style Comments using the LSP

2 participants