tpope / vim-fireplace

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

Clojure CLI support #357

Closed metasoarous closed 3 years ago

metasoarous commented 5 years ago

First, thanks for all your wonderful work on Fireplace!

I'm just starting on a project using Clojure CLI, and finding that I'm not immediately able to figure out how to connect Fireplace to the clj. Has anyone figured this out? If so, can we add something to the README about it? If not, can I please make this a feature requestion?

Thanks in advance!

tpope commented 5 years ago

Fireplace needs nREPL. I'm not aware of any turnkey solutions for firing up an nREPL server from 'clj, but if one exists I'd be happy to document it.

metasoarous commented 5 years ago

Looks like there is a fairly straightforward solution to this!

https://stackoverflow.com/a/54066339/177677

whence

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -m nrepl.cmdline

Also, there's this ~/.clojure/deps.edn snippet which let's you just run clj -A:nrepl: https://github.com/seancorfield/dot-clojure/blob/master/deps.edn#L49-L50

tpope commented 5 years ago

Awesome, is there a cider-nrepl variant? Fugitive needs it for some features.

On Wed, Jul 31, 2019 at 17:50 Christopher Small notifications@github.com wrote:

Looks like there is a fairly straightforward solution to this!

https://stackoverflow.com/a/54066339/177677

whence

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -m nrepl.cmdline

Also, there's this ~/.clojure/deps.edn snippet which let's you just run clj -A:nrepl: https://github.com/seancorfield/dot-clojure/blob/master/deps.edn#L49-L50

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/tpope/vim-fireplace/issues/357?email_source=notifications&email_token=AAAAC6VOX3T4NZKFESBBKCDQCICKNA5CNFSM4IIG2522YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3IVMJA#issuecomment-517035556, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAAC6RCRK2G45PSUNE4NL3QCICKNANCNFSM4IIG252Q .

metasoarous commented 5 years ago

Looks like it?

https://github.com/clojure-emacs/cider-nrepl#via-clj

I'll give it a try and report back about whether it works.

metasoarous commented 5 years ago

Yup! Seems to work! I haven't tried from deps.edn, but I'm assuming it should work just fine.

metasoarous commented 5 years ago

Update: tried it out in deps.edn and it works that way as well.

AlexChalk commented 4 years ago

Clojure incantation currently working for me: https://docs.cider.mx/cider-nrepl/usage.html#_via_clj

bbatsov commented 4 years ago

Yeah, that's exactly what you need. We've added a main function to nREPL so it can be easily started with clj with whatever middleware someone might need.

benknoble commented 4 years ago

I've had good luck with the following (may be same info in the links, but just to have the code right in front of you):

; ~/.clojure/deps.edn
{:aliases
 {,,,
  :cider
  {:extra-deps {cider/cider-nrepl {:mvn/version "RELEASE"}}
   :main-opts ["-m" "nrepl.cmdline"
               "--middleware" "[cider.nrepl/cider-middleware]"]}
  ,,,}}

Then you can use clojure -A:cider to start up the required cider nREPL. If you do this before starting vim, fireplace will connect automatically.

I wrapped it up in

#! /bin/sh
# file: fireplace
# put it somewhere on $PATH

exec clojure -C:runner -A:cider "$@"

Now you can just run fireplace before launching vim.

(:runner is my standard alias which puts test on the path; I included it only to allow running tests from fireplace when they're not in the src directory.)

kovasap commented 3 years ago

I'm running a figwheel project with:

clojure -m figwheel.main -b dev

and am trying to go down this path to get fireplace set up so that I can use https://github.com/venantius/vim-cljfmt.

I tried @benknoble 's configuration, running my project like:

clojure -A:cider -m figwheel.main -b dev

This gives me:

nREPL middleware: figwheel.main has no namespace

Anyone here have any idea what this means? I'm new to clojure and feel like I'm missing something obvious...

metasoarous commented 3 years ago

Hi @kovasap. The :main-opts entry from the :cider alias has it's own -m invocation, which may be conflicting with -mfigwheel.main. You may actually not need to run cider if you're using figwheel; I actually haven't used it in a while.

FWIW, if you're new to cljs, I'd recommend Shadow-CLJS, as it makes it much easier to deal with javascript/npm libraries, and covers all the functionality of figwheel, and IMHO is a bit easier to use overall. With shadow, you just run shadow-clj watch <build-id>, (build-id being something you specify in your shadow-cljs.edn) and it starts a REPL for you that you can connect to with Fireplace using vim command :Connect <repl-port> (repl-port being printed out for you). Then you can run :CljEval (shadow/repl :app).

Sorry to throw even more things at you; If you're committed to getting figwheel to work for now, you may want to open a fresh issue, search around through the issues a bit more, or visit the Clojurians slack (https://clojurians.slack.com/) so see if you can't find folks there who might be able to help. In general, people tend to be pretty helpful to newcomers.

Good luck!

kovasap commented 3 years ago

Thanks for the suggestion! I'll try Shadow-CLJS the next time I find time to work on my project : )