cider icon indicating copy to clipboard operation
cider copied to clipboard

cider-repl-set-ns changes repl session from cljs:shadow to clj

Open kakaLQY opened this issue 2 years ago • 5 comments

Expected behavior

cider-repl-set-ns should not change the cider-repl session type.

Actual behavior

cider-repl-set-ns in a cljs:shadow session will change the session type to clj.

Steps to reproduce the problem

In a shadow-cljs project, run cider-repl-set-ns. The cider-repl session will be changed from cljs:shadow to clj by checking with sesman-browser.

Environment & Version information

CIDER version information

;; CIDER 1.5.0-snapshot (package: 1.5.0-snapshot), nREPL 0.9.0
;; Clojure 1.10.3, Java 11.0.15

Lein / Clojure CLI version

1.11.1

Emacs version

28.1

Operating system

NixOS

JDK distribution

openjdk version "11.0.15" 2022-04-19

Hints

It seems the bug is introduced by https://github.com/clojure-emacs/cider/commit/5f705b0a3a0266e4e64bc37016135a6284d2321f, as after reverted, the bug will be gone.

kakaLQY avatar Aug 06 '22 13:08 kakaLQY

+1, on CIDER 1.5.0-snapshot, clj 1.10.0, emacs 28.1, ubuntu, jdk 11.0.16+8-post-Ubuntu-0ubuntu122.04

caumond avatar Aug 30 '22 15:08 caumond

This behaviour seems to somehow be triggered through the cider-repl--state-handler function, and specifically the following snippet:

(when (and repl-type cider-repl-auto-detect-type)
    (cider-set-repl-type repl-type))

For whatever reason, the response object seems to indicate a repl-type of clj in my shadow-cljs repl.

jellelicht avatar Sep 13 '22 23:09 jellelicht

Using cider-tooling-eval passes along 'tooling to nrepl-request:eval. I'm guessing this leads to using the 'wrong' session somehow, one where the repl-type is (still) clj instead of cljs.

jellelicht avatar Sep 14 '22 13:09 jellelicht

That's an interesting edge case as there's just a single tooling session and it's a Clojure session. Perhaps for ClojureScript we can run this in the ClojureScript eval session instead, although it's going to mess a bit with the eval results vars (e.g. *1).

bbatsov avatar Sep 14 '22 13:09 bbatsov

@bbatsov Perhaps a stupid idea, but maybe we can temporarily re-bind cider-repl-auto-detect-type to be falsey?

jellelicht avatar Sep 15 '22 10:09 jellelicht

I got bitten by this as well when running a cljs REPL using figwheel-main. Whenever I switch to a namespace using cider-repl-set-ns, the cider-repl-type is changed to clj. When I type in code in the REPL, it gets evaluate just fine - but the REPL jumps back to user.cljs as the parameter gets switched back to cljs after the evaluation. Specs: CIDER 1.5.0, Clojure 1.10.2, Java 17.0.1, Emacs 28.2, Mac OS Ventura 13.0.

tvirolai avatar Oct 27 '22 11:10 tvirolai

I'm having the same issue with cider 1.6.0-SNAPSHOT actually, would be nice to have a workaround at least

AndreaCrotti avatar Nov 22 '22 15:11 AndreaCrotti

The workaround I have is to navigate to the shadow repl manually, enter the namespace of the file, navigate back to the file and eval/load it with ctrl-k. I've been meaning to put this into an elisp fn. If I do I'll post it here.

scott-kl avatar Nov 22 '22 17:11 scott-kl

Another way I found is to just do a cider-set-repl-type on the shadow cljs repl after I messed it up, not great though I wonder why it even thinks it's a clj repl in the first place.

AndreaCrotti avatar Nov 23 '22 13:11 AndreaCrotti

@yuhan0 Can you take a look at this?

bbatsov avatar Dec 08 '22 10:12 bbatsov

This is the hack I came up with if anybody wants a quick fix.

(defun switch-to-shadow ()
  (interactive)
  (cider-switch-to-repl-buffer t)
  (sit-for 0.5) ;; above call doesn't come back in time to reset the repl??
  (cider-set-repl-type "cljs"))

scott-kl avatar Jan 25 '23 04:01 scott-kl