tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.75k stars 139 forks source link

Interrupt Broken? #402

Closed bhurlow closed 2 years ago

bhurlow commented 2 years ago

I'm finding that interrupting form evaluation with <C-c> doesn't seem to send an interrupt op to nrepl. Though control is returned to vim, evaluation of the next form is blocked by the currently running eval which may potentially block forever. Here's how I'm reproducing this:

Using vim 8.2 for arm, +python3

Starting an nrepl instance with no outside deps:

 clojure -Sdeps '{:deps {nrepl {:mvn/version "0.9.0"}}}' -m  nrepl.cmdline

setting my .vimrc to only use vim-fireplace to rule out any additional plugin clashes

call plug#begin()
Plug 'tpope/vim-fireplace'
call plug#end()

Then in a clojure buffer (src/foo/bar.clj):

(ns foo.bar)

(Thread/sleep 10000)
(+ 200 200)

If I first eval the sleep form, then issue an interrupt, then finally attempt to eval the (+ 200 200) form, it blocks for 10s until returning 400.

This thread indicates this was at one point handled via a catch for catch /^Vim:Interrupt$/ but that was replaced.

I found that adding a similar catch to fireplace#wait() like this properly cancels the thread.

Is there a reason that approach is not supported? Are other folks encountering this?

tpope commented 2 years ago

Using finally instead of catch allows the exception to propagate. The problem is that interactive eval does waiting differently so that it can talk to stdin, so it needs its own interrupt handler.

bhurlow commented 2 years ago

@tpope ok great thanks for clarifying. Does that mean interrupt is still handled elsewhere if/when the exception propagates up? What would be the non-interactive eval mode for fireplace?

tpope commented 2 years ago

The exception bubbles up and is displayed as an error message.

Non-interactive eval would include literally anything else, e.g. doc lookup, jump to definition, etc.

bhurlow commented 2 years ago

@tpope fix works great, thank you