clojure-emacs / clj-refactor.el

A CIDER extension that provides powerful commands for refactoring Clojure code.
GNU General Public License v3.0
771 stars 111 forks source link

cljr--inject-jack-in-dependencies adds refactor-nrepl/refactor-nrepl twice when cider-preferred-build-tool is not lein #511

Closed fvides closed 2 years ago

fvides commented 2 years ago

Expected behavior

The function cljr--inject-jack-in-dependencies should add the refactor-nrepl/refactor-nrepl once when cider-preferred-build-tool is not lein

Actual behavior

When cider-preferred-build-tool the function cljr--inject-jack-in-dependencies adds refactor-nrepl/refactor-nrepl twice, one to cider-jack-in-dependencies and another to cider-jack-in-lein-plugins.

So when we start the program it fails with a message like:

error in process sentinel: Could not start nREPL server: Error while parsing option "--config-data {:deps {refactor-nrepl/refactor-nrepl {:mvn/version \"3.3.2\"} nrepl/nrepl {:mvn/version \"0.9.0\"} refactor-nrepl/refactor-nrepl {:mvn/version \"3.3.2\"} cider/cider-nrepl {:mvn/version \"0.27.4\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]\"]}}}": java.lang.IllegalArgumentException: Duplicate key: refactor-nrepl/refactor-nrepl

Steps to reproduce the problem

  1. Start an emacs session making sure that cider-preferred-build-tool is not 'lein
  2. Eval cider-jack-in-clj to a non-lein project

Environment & Version information

clj-refactor.el version information

clj-refactor 3.3.2 (package: 3.3.3), refactor-nrepl is unreachable

CIDER version information

Include here the version string displayed when CIDER's REPL is launched. Here's an example:

;; CIDER 1.2.0 (Nice), nREPL 0.9.0
;; Clojure 1.10.3, Java 16.0.2

Leiningen or Boot version

Emacs version

27.1

Operating system

Ubuntu Linux

Possible fix

I've solved this for me like this in function cljr--inject-jack-in-dependencies:

(if (not (eq cider-preferred-build-tool 'lein))
        (cider-add-to-alist 'cider-jack-in-dependencies
                            "refactor-nrepl/refactor-nrepl" cljr-injected-middleware-version)

    (add-to-list 'cider-jack-in-lein-plugins `("refactor-nrepl/refactor-nrepl" ,cljr-injected-middleware-version
                                                 :predicate cljr--inject-middleware-p)))

It only add the dependency to cider-jack-in-lein-plugins when the cider-preferred-build-tool is lein, not sure if this is in fact the right thing but it seems logical. If you want I could prepare a PR.

vemv commented 2 years ago

Hi, thanks for the report!

CIDER has to be absolute latest in this specific case, e.g. a snapshot from Git master or a melpa snapshot.

Most likely the issue will disappear if you upgrade cider.

Cheers - V

vemv commented 2 years ago

Did you get to try a more recent CIDER?

vemv commented 2 years ago

Even though as of https://github.com/clojure-emacs/clj-refactor.el/issues/511#issuecomment-1044371229 the issue was fixed in cider master, now it's further fixed via https://github.com/clojure-emacs/cider/commit/956984faa1f8a5edc9eb94eacdf530cb9404850b .

Again, this change is currently reachable by using a MELPA snapshot or a git clone.

We'll cut a stable CIDER release within a week.

vemv commented 2 years ago

In case it helps, CIDER 1.3.0 was released today!