nvim-metals icon indicating copy to clipboard operation
nvim-metals copied to clipboard

Command to interrupt worksheets

Open simlei opened this issue 2 years ago • 1 comments

Describe the feature

Worksheets (*.worksheet.sc) provide a good way to test out stuff quickly. However, I have not found a way to stop their evaluation in the case that an infinite calculation was issued in one of the lines in the worksheet. Example using ZIO 2.0.0-RC2

import zio.*
import zio.stream.*
val stream = ZStream.iterate(0)(_ - 1)
val prog = for {
  out <- stream.find(_ == 100).runHead
} yield out
Runtime.default.unsafeRunSync(prog)

Potential ways to implement

A command to stop the evaluation would be nice. Idea: :MetalsWorksheetCancelEvaluation. I don't know how specifically this would be implemented though.

simlei avatar May 30 '22 09:05 simlei

Thanks for creating this @simlei!

Example using ZIO 2.0.0-RC2

Just in case you didn't know, you can also put the imports right into the worksheet, so when you share it, it can be ran right away.

import $dep.`dev.zio::zio:2.0.0-RC2` // you can use $dep or $ivy
import $dep.`dev.zio::zio-streams:2.0.0-RC2`

So looking at this, I think what we can do is start supporting metals/slowTask. I'm glad you brought this up because I just realized that the docs here are out of date, there is only a true or false available, not status-bar. However, we can sort of steal that idea. We can say that nvim-metals is a slowTaskProvider and when we get the notifications about the slow task we can store the id of the actual request and then display the message and secondsElapsed just like we do with metalsStatus. We can also put a little like (cancellable) message or icon or something in the status to notify the user it can be cancelled, and there can just be a :MetalsCancelSlowTask command that a user can use. This will work not only for worksheets, but any slow task.

EDIT: I played around with this a bit, and there are more slowTasks being sent than I expected which sort of makes it hard to deal with since the slowTask handler expects a return value back. I'll need to play around a bit more to see if I can figure something out.

ckipp01 avatar May 30 '22 20:05 ckipp01

So this is a bit of a hack, but for now since https://github.com/scalameta/metals/pull/6013 is merged, you can utilize the cancel compilation command, which will now also cancel the worksheet evaluation.

ckipp01 avatar Feb 16 '24 11:02 ckipp01