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

`FireplaceK` fails if `clojure.repl` is not loaded #392

Closed frenchy64 closed 3 years ago

frenchy64 commented 3 years ago

I don't think this is a problem with lein repl, but other tools like Clojure CLI don't automatically load clojure.repl. Using K in normal mode throws:

Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:440).
clojure.repl

I then need to (require 'clojure.repl) manually to have K work.

I think this is fixable by changing calls like (#'clojure.repl/namespace-doc ...) to an inlining of clojure.core/requiring-resolve (which is a newer Clojure function and shouldn't be used directly for compatibility):

((clojure.core/or
   (clojure.core/resolve 'clojure.repl/namespace-doc)
   (do (clojure.core/require 'clojure.repl)
       (clojure.core/resolve 'clojure.repl/namespace-doc)))
 ...)
tpope commented 3 years ago

Seems like a sound approach. Note that codepath is the fallback for when cider-nrepl is missing, so it might behoove you to investigate what's up with that.

frenchy64 commented 3 years ago

Ah, good point. I often just live without it, so the fallback is for people like me :)

frenchy64 commented 3 years ago

The codepath was in a different place than I expected, I'm less sure it's related to middleware now. https://github.com/tpope/vim-fireplace/pull/394

tpope commented 3 years ago

A simpler solution might be to toss a require into this initialization code:

https://github.com/tpope/vim-fireplace/blob/07b0256b08e0da6d31200663cbe6d6f8c995a287/autoload/fireplace/transport.vim#L213-L217

This code only runs if there's no cider-nrepl.

tpope commented 3 years ago

Actually this code is doing goofy eval shenanigans on the response so you will have to be mindful to avoid that. Putting (clojure.core/require 'clojure.repl) at the very end ought to do it.

frenchy64 commented 3 years ago

Seems to work putting it at the end! Updated the PR.