Description
Expected behavior
For a running nrepl on localhost, I expected (cider-select-endpoint)
to allow me to select ports on which nrepl is running.
(I use this to connect ob-clojure buffers to cider when doing literate programming and a bit of completion comes handy)
Fixes #3390
Actual behavior
It requires me to input the port manually.
Steps to reproduce the problem
- cider-jack-in without a project
- cider-connect from another clj buffer
- follow instructions to get to the cider session you opened before
- see that there are no available ports
or more specifically:
- eval in emacs
(cider--running-nrepl-paths)
- see an empty output sigh!
My solution
Just for curiosity, I redefined cider--running-nrepl-paths
(which seems to be the culprit) as follows:
(defun cider--running-nrepl-paths ()
"Retrieve project paths of running nREPL servers.
Use `cider-ps-running-nrepls-command' and
`cider-ps-running-nrepl-path-regexp-list'."
(seq-uniq
(seq-map
(lambda (b)
(with-current-buffer b default-directory))
(seq-filter
(lambda (b) (string-prefix-p "*cider-repl" (buffer-name b)))
(buffer-list)))))
That way things seem to work fine (for localhost).
I opened an issue because I think cider-ps-running-nrepls-command
and cider-ps-running-nrepl-path-regexp-list
are somewhat outdated. I replaced the behavior going via Emacs active buffers.
Any chance you can clarify why cider is looking for active nrepl via a terminal command (greping for leiningen -- I didn't find anything using that command manually)?
If this solution seems useful, I could look into opening a PR :)
CIDER version information
1.8.0-snapshot
Lein / Clojure CLI version
lein 2.9.1 / 1.10.3
Emacs version
28.1
Operating system
Ubuntu 22.04
Activity
vemv commentedon Aug 2, 2023
Hi!
Thanks for the detailed issue.
This very likely aims to make it possible to connect to repls that were created outside of CIDER, in the terminal, especially if their pwd is not the
current-directory
of any Emacs buffer.I agree. However I think we could take the current
cider-locate-running-nrepl-ports
impl from:to:
java
processes that don't containlein
in itjava
invocations--port
argument parsing (this is anrepl.cmdline
flag), or fallback to lsof*cider-repl
s, callcider--gather-connect-params
on each, extract the port param from thereseq-uniq
s all of themWDYT?
bbatsov commentedon Aug 2, 2023
Sounds reasonable.
ag91 commentedon Aug 2, 2023
I looked into it a bit and a thing to note:
cider-locate-running-nrepl-ports
returns pairs path-port (e.g.,'(("~" "41655"))
).Due to that, for my use case I changed
cider--running-nrepl-paths
instead.To make things work in
cider-locate-running-nrepl-ports
I may use a terminal command likepwdx
to capture the working dir of those process identifiers I find.Also would it be wrong to look for processes that mention
nrepl
(I have-m nrepl.cmdline
in the processes I spin via cider, but i guess maybe that is unique to Clj Cli)? Otherwise I think I may also catch java processes that Cider cannot connect to.And how do you usually test these kind of changes? I am using a Linux machine, so I will be confident for those bash commands, but MacOS (and Windows?!).
vemv commentedon Aug 3, 2023
Yes, I had the impression that that's for better usability (this way one can present the "context" for each port in the
completing-read
)"nrepl.cmdline"
can be present in Clojure CLI and vanilla java invocations (the latter might become increasingly common because of #3364)I'm not sure about inspecting java processes that match
nrepl
but notnrepl.cmdline
. I think it can be done, provided that we present a short, informative context in thecompleting-read
(like the pwd, suffixed by" other"
if there was another java process in the same pwd)...If including such processes excessively complicated things, I'd be willing to exclude them.
Currently
defvar cider-ps-running-nrepls-command
has the fixed"ps u | grep leiningen"
value. It's not even a defcustom 😅 so it doesn't matter much if it doesn't work on Windows.As long as we stick to simple primitives like ps/grep, we can be fine with no testing / just a one-off round of QAing. I can try it on my macbook while reviewing a PR.
Cheers - V
add entry to changelog
add entry to changelog
Enhance `cider-connect` to show all nREPLs available ports, instead o…
cider-connect
to show all nREPLs available ports, instead of only Leiningen ones #3399Enhance `cider-connect` to show all nREPLs available ports, instead o…
Enhance `cider-connect` to show all nREPLs available ports, instead o…
ag91 commentedon Aug 11, 2023
thank you @vemv and @bbatsov, it is easier to connect now :D
vemv commentedon Aug 12, 2023
🍻