-
-
Couldn't load subscription status.
- Fork 651
Description
Expected behavior
(setq cider-injected-middleware-version "0.27.4")Should update the cider-jack-in* command to use version 0.27.4 of cider/cider-nrepl.
;; Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/piggieback {:mvn/version "0.5.2"} refactor-nrepl/refactor-nrepl {:mvn/version "3.2.0"} 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,cider.piggieback/wrap-cljs-repl]"]}}}' -Mdev:cider/nrepl Actual behavior
cider/cider-nrepl version in generated commandline is unchanged and still "0.28.0". IE:
;; Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/piggieback {:mvn/version "0.5.2"} refactor-nrepl/refactor-nrepl {:mvn/version "3.2.0"} cider/cider-nrepl {:mvn/version "0.28.0"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -Mdev:cider/nrepl However, if the setq is called prior to cider require, then the value is updated to 0.27.4.
Steps to reproduce the problem
Use the setq above to update cider-injected-middleware at runtime, and then run cider-jack-in-clj or cider-jack-in-cljs. The injected plugins will stay 0.28.0.
Workaround Fix
The problem appears to be that 'cider-jack-in-lein-plugins is updated at top-level during require from the current value of cider-injected-middleware-version. This happens at
Lines 467 to 468 in 8bb6717
| (cider-add-to-alist 'cider-jack-in-lein-plugins | |
| "cider/cider-nrepl" cider-injected-middleware-version) |
(cider-add-to-alist 'cider-jack-in-lein-plugins "cider/cider-nrepl" "0.27.4")Is sufficient to update the injected plugin.
It's not entirely clear to me what the best fix is. Initially I thought it would be easiest to ensure the top level call to cider-jack-in-lein-plugins is calculated as late as possible, but it's used in cider-jack-in-normalized-lein-plugins, cider-clojure-cli-jack-in-dependencies, cider-shadow-cljs-jack-in-dependencies, cider-jack-in-cljs and cider-jack-in-clj&cljs at minimum, so it appears to have a pretty wide surface area.
It's also not clear that the cider-add-to-alist behavior should be disabled, if 'cider-jack-in-lein-plugins is directly mutated it seems like it should override the value, and I suspect there is .dir-locals or package setup code in the wild doing that.
However, it is still confusing to have a specific defcustom that is ignored unless it's at the first require. It breaks the published docs and API, but I think the easiest fix might be to remove the defcustom and document mutating the plugins list directly. Otherwise I think it might require a careful rewrite of the access to cider-jack-in-lein-plugins to ensure it can calculate the version at runtime.
I also appreciate this is a very edge case error, so maybe it's best just to improve the documentation on it and leave it be for now.
Environment & Version information
CIDER version information
;; CIDER 1.3.0-snapshot (package: 20220113.610), nREPL 0.9.0 ;; Clojure 1.10.3, Java 1.8.0_312 Emacs version
GNU Emacs 29.0.50 (build 14, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-01-16
Operating system
Ubuntu 20.04