Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:select nil in popup-rules for cider REPL buffer causes error on cider-jack-in-cljs #2515

Closed
glittershark opened this issue Nov 7, 2018 · 12 comments

Comments

@glittershark
Copy link
Contributor

Expected behavior

cider-jack-in-cljs and cider-jack-in-clj&cljs both launch a repl, then launch figwheel as a sibling

Actual behavior

If I'm in a cljs file and I run either of the above, I get the following messages:

[nREPL] Starting server via /usr/bin/lein update-in :dependencies conj \[nrepl\ \"0.4.5\"\] -- update-in :dependencies conj \[cider/piggieback\ \"0.3.10\"\] -- update-in :plugins conj \[refactor-nrepl\ \"2.4.0\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.19.0-SNAPSHOT\"\] -- repl :headless :host localhost...
[nREPL] server started on 45765
[nREPL] Establishing direct connection to localhost:45765 ...

Followed by the following error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  nrepl-send-request(("op" "eval" "code" "(when (clojure.core/resolve 'clojure.main/repl-requires)\n       (clojure.core/map clojure.core/require clojure.main/repl-requires))" "inhibit-cider-middleware" "true") #f(compiled-function (resp) #<bytecode 0x1ffd049241ad>) nil nil)
  nrepl-send-sync-request(("op" "eval" "code" "(when (clojure.core/resolve 'clojure.main/repl-requires)\n       (clojure.core/map clojure.core/require clojure.main/repl-requires))" "inhibit-cider-middleware" "true") nil)
  cider-repl-require-repl-utils()
  cider-repl-init(#<buffer *cider-repl urb/ciml:localhost:45765(pending-cljs)*>)
  cider--connected-handler()
  run-hooks(nrepl-connected-hook)
  nrepl-start-client-process("localhost" 45765 #<process nrepl-server> #f(compiled-function (_) #<bytecode 0x1ffd049b1575>))
  cider-nrepl-connect((:project-dir "~/code/urb/ciml/" :jack-in-cmd "/usr/bin/lein update-in :dependencies conj \\[nrepl\\ \\\"0.4.5\\\"\\] -- update-in :dependencies conj \\[cider/piggieback\\ \\\"0.3.10\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.4.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.19.0-SNAPSHOT\\\"\\] -- repl :headless :host localhost" :host "localhost" :port 45765 :project-dir "~/code/urb/ciml/" :server #<process nrepl-server> :server-command "/usr/bin/lein update-in :dependencies conj \\[nrepl\\ \\\"0.4.5\\\"\\] -- update-in :dependencies conj \\[cider/piggieback\\ \\\"0.3.10\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.4.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.19.0-SNAPSHOT\\\"\\] -- repl :headless :host localhost" :cljs-repl-type figwheel :repl-init-function #f(compiled-function () #<bytecode 0x1ffd049b1561>) :session-name nil :repl-type "pending-cljs"))
  cider-connect-sibling-cljs((:project-dir "~/code/urb/ciml/" :jack-in-cmd "/usr/bin/lein update-in :dependencies conj \\[nrepl\\ \\\"0.4.5\\\"\\] -- update-in :dependencies conj \\[cider/piggieback\\ \\\"0.3.10\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.4.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.19.0-SNAPSHOT\\\"\\] -- repl :headless :host localhost") #<buffer  *nrepl-server urb/ciml:localhost*>)
  #f(compiled-function (server-buffer) #<bytecode 0x1ffd04948429>)(#<buffer  *nrepl-server urb/ciml:localhost*>)
  nrepl-server-filter(#<process nrepl-server> "nREPL server started on port 45765 on host localhost - nrepl://localhost:45765\n")

Steps to reproduce the problem

I can reproduce this on a fresh project created with the lein-re-frame template:

lein new re-frame repro +cider

Open any cljs buffer in the resulting project, and run M-x cider-jack-in-cljs RET fighweel RET

Note that I have tried the troubleshooting tips mentioned by #1390 (eg reinstalling cider), and that didn't appear to help

Environment & Version information

CIDER 0.19.0snapshot

CIDER version information

;; CIDER 0.19.0snapshot, nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_181

Lein version

❯ lein --version
Leiningen 2.8.1 on Java 1.8.0_181 OpenJDK 64-Bit Server VM

Emacs version

26.1

Operating system

Arch Linux

@mallt
Copy link
Contributor

mallt commented Nov 8, 2018

I suppose this is caused by setting the variable cider-default-cljs-repl as string instead of as symbol. Can you try to set it as follows:

(setq cider-default-cljs-repl 'figwheel)

@glittershark
Copy link
Contributor Author

Nope, still happening

@mallt
Copy link
Contributor

mallt commented Nov 8, 2018

Maybe the value is overwritten in .dir-locals.el?

@glittershark
Copy link
Contributor Author

Nope, sorry. Fwiw before setting this I was getting prompted for the cljs repl type to use

@glittershark
Copy link
Contributor Author

Just tried nerfing my entire ~/.emacs.d/.local/packages to no avail

@glittershark
Copy link
Contributor Author

Been tracing through this with edebug trying to narrow down the problem, and think I may have gotten something.
Going to step into it further, but somewhere between the beginning of cider-init-repl and the call to (cider-repl-require-repl-utils), (cider-current-repl) goes from the expected (clj) repl to nil.

@glittershark
Copy link
Contributor Author

(current-buffer) also appears to be changing from where it's set (via with-buffer) to the clj repl here back to the .cljs file that I ran cider-jack-in-cljs from.

@glittershark
Copy link
Contributor Author

More narrowing down -- looks like the call to display-buffer to show the REPL buffer is somehow resetting the current buffer back to the cljs file - adding an extra with-current-buffer around the call to cider-repl-require-repl-utils gives me a new error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  cider--nrepl-version()
  cider--check-required-nrepl-version()
  cider--connected-handler()
  run-hooks(nrepl-connected-hook)
  nrepl-start-client-process("localhost" 44327 #<process nrepl-server> #f(compiled-function (_) #<bytecode 0x1fef486643a5>))
  cider-nrepl-connect((:project-dir "~/code/urb/ciml/" :jack-in-cmd "/usr/bin/lein update-in :dependencies conj \\[nrepl\\ \\\"0.4.5\\\"\\] -- update-in :dependencies conj \\[cider/piggieback\\ \\\"0.3.10\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.4.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.19.0-SNAPSHOT\\\"\\] -- repl :headless :host localhost" :cljs-repl-type figwheel :do-prompt nil :host "localhost" :port 44327 :project-dir "~/code/urb/ciml/" :server #<process nrepl-server> :server-command "/usr/bin/lein update-in :dependencies conj \\[nrepl\\ \\\"0.4.5\\\"\\] -- update-in :dependencies conj \\[cider/piggieback\\ \\\"0.3.10\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.4.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.19.0-SNAPSHOT\\\"\\] -- repl :headless :host localhost" :repl-init-function nil :repl-type "clj" :session-name nil))
  cider-connect-sibling-clj((:project-dir "~/code/urb/ciml/" :jack-in-cmd "/usr/bin/lein update-in :dependencies conj \\[nrepl\\ \\\"0.4.5\\\"\\] -- update-in :dependencies conj \\[cider/piggieback\\ \\\"0.3.10\\\"\\] -- update-in :plugins conj \\[refactor-nrepl\\ \\\"2.4.0\\\"\\] -- update-in :plugins conj \\[cider/cider-nrepl\\ \\\"0.19.0-SNAPSHOT\\\"\\] -- repl :headless :host localhost" :cljs-repl-type figwheel :do-prompt nil) #<buffer  *nrepl-server urb/ciml:localhost*>)
  #f(compiled-function (server-buffer) #<bytecode 0x1fef484b5bf1>)(#<buffer  *nrepl-server urb/ciml:localhost*>)
  nrepl-server-filter(#<process nrepl-server> "nREPL server started on port 44327 on host localhost - nrepl://localhost:44327\n")

@glittershark
Copy link
Contributor Author

glittershark commented Nov 9, 2018

After reading the source, that makes sense - there are other functions in the caller that rely on the current buffer being correct, so when the with-current-buffer scope ends they still get the wrong buffer.

Without digging too deep into why display-buffer is changing the current buffer, this (admittedly pretty hacky) patch fixes the problem:

diff --git a/cider-repl.el b/cider-repl.el
index 261b5bbb..db1cd3f7 100644
--- a/cider-repl.el
+++ b/cider-repl.el
@@ -315,7 +315,10 @@ client process connection.  Unless NO-BANNER is non-nil, insert a banner."
   (when cider-repl-display-in-current-window
     (add-to-list 'same-window-buffer-names (buffer-name buffer)))
   (pcase cider-repl-pop-to-buffer-on-connect
-    (`display-only (display-buffer buffer))
+    (`display-only
+     (let ((orig-buffer (current-buffer)))
+       (display-buffer buffer)
+       (set-buffer orig-buffer)))
     ((pred identity) (pop-to-buffer buffer)))
   (cider-repl-set-initial-ns buffer)
   (cider-repl-require-repl-utils)

@rschmukler
Copy link

Just commenting that I ran into this as well and @glittershark's patch fixed it for me too. We do share a lot of config (doom-based emacs) but fwiw.

@kommen
Copy link
Contributor

kommen commented Nov 19, 2018

Can you check if this was maybe fixed with #2484?

@glittershark
Copy link
Contributor Author

It wasn't, directly, but the update I ran did fix it via another means - specifically doomemacs/doomemacs#1012, which resolves what was causing the call to display-buffer to change current-buffer.

I think I'm going to submit the above patch as a PR anyway, since it generally makes Cider more robust against these sorts of settings.

@glittershark glittershark changed the title (wrong-type-argument stringp nil) on cider-jack-in-cljs (with figwheel), but not clj :select nil in popup-rules for cider REPL buffer causes error on cider-jack-in-cljs Nov 19, 2018
glittershark added a commit to glittershark/cider that referenced this issue Nov 19, 2018
If the user has `:select nil` in their popup rules for the Cider REPL
buffer, the call to `display-buffer` to display the repl buffer while
initializing it will reset the `current-buffer` to the buffer the user
ran `jack-in` from, which breaks any successive calls to
`cider-current-repl`. Resetting the current buffer back to the original
buffer after `display-buffer` is resilient against this config change,
without breaking anything else in the case the config is absent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants