This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-25
Channels
- # announcements (22)
- # babashka (9)
- # beginners (33)
- # biff (12)
- # calva (17)
- # cider (64)
- # cljdoc (3)
- # cljfx (16)
- # clojure (125)
- # clojure-bay-area (14)
- # clojure-europe (15)
- # clojure-norway (64)
- # clojure-uk (2)
- # clojurescript (7)
- # conjure (1)
- # core-async (4)
- # cursive (6)
- # data-science (14)
- # datahike (8)
- # datomic (6)
- # defnpodcast (4)
- # emacs (5)
- # events (1)
- # hyperfiddle (15)
- # leiningen (17)
- # lsp (8)
- # membrane (27)
- # off-topic (25)
- # podcasts-discuss (4)
- # polylith (6)
- # portal (21)
- # reagent (11)
- # releases (1)
- # shadow-cljs (36)
- # slack-help (2)
- # sql (1)
- # squint (131)
- # testing (12)
- # xtdb (7)
ℹ️ We have released the smaller release CIDER 1.9.0 ("Barcelona") mostly to group a batch of Inspector new commands, bugfixes and presentational improvements.
Feel free to go over the https://github.com/clojure-emacs/cider/releases/tag/v1.9.0 / https://docs.cider.mx/cider/1.9/debugging/inspector.html!
We have more Inspector goodness on the radar. Think tap>
refinements and cljs compatibility 👀
Question - when evaluating things I like to use C-c C-p cider-pprint-last-sexp. However if there’s an error the result window pops up with nothing in it, and I can only find there was an error by checking the repl. When I use C-x C-e I get a nice error overlay now, but if I use C-c C-p, how do I know there was an error? Can it automatically popup an error window or overlay too? I don’t have any config set, just using cider / clojure-mode out the box.
> However if there’s an error the result window pops up with nothing in it,
Sounds like an issue, it should be conveyed either as an overlay or as *cider-error*
Feel free to report it!
For some reasons related to my ssh setup, I needed to "customize" 2 parts of the full string used by CIDER to execute the jackin, I marked them in bold here: --- /home/vscode/.asdf/shims/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.30.0"} refactor-nrepl/refactor-nrepl {:mvn/version "3.6.0"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "-p" "12345" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]}}}' -M:cider/nrepl --- Is there a way in CIDER to achieve this customization ?
you can edit the string CIDER uses to connect. You can also leverage nrepl’s own https://nrepl.org/nrepl/1.0/usage/server.html#server-configuration and make a local nrepl.edn
file that would include the port you want to use
yes, that does work So I manged to start the nrepl server on a fixed port.
Now I have an other complication for using "cider-jack-in".
My "setup" tunnels the remote 12345 port back to localhost.
So the implicite "connect" done by cider-jack-in
should connect to "localhost:12345" (whch would work), but as I edit the files over TRAMP, it tries "remote-host:12345", which does not work...
So cider-jack-in
fails, (but it leaves the server started),
so I can do cider-connect localhost:12345
So basically I would need a "fallback-to-localhost".....
I agree, I have an unsual setup. (but it is the default setup when using "devpod" (https://devpod.sh/)
i’m not sure i’m following. sounded like jack in succeeds but editing files is broken. But then you said jack-in is broken.
First problem was solved. Making sure cider-jack-in
starts server on remote host correctly (fixing port to 12345 and using non standrd clojure path)
This is working now,
but with these kinds of setups, I’d say the following strategy is most likely to work. Start up nrepl from a terminal the “proper” way so you know it is correct. and then cider-connect to it. see if you can connect and edit files and all that jazz. Once you know what the startup form should be, then turn to getting CIDER to start it up correctly
Yes, I agree. I came to that conclusion as well.
But I was investigating if I can use teh "compfort" of cider-jack-in
as well for my setup.
so does everything work correctly if you start your project and nrepl in a terminal and connecting from CIDER?
cider-jack-in
and its configuration options do not handle "all cases", mine is not handled / configurable.
if you do c-u m-x cider-jack-in
you can edit the connection string. Can you edit it such that it works completely? Once you know exactly what connection form works it should be decently simple to get it configurable to get you there
That the relationship between "emacs buffer name having a host name in case of TRAMP" could still mean "connect to localhost"
if you can correctly cider-connect to a startup form, can you edit the jack-in startup form and have a working setup?
my buffer says "xxx.clj@a-host`
because i understood you said that if you start up the project in a terminal you can cider connect to it and everything works properly
and cider-jack-in or cider-connect shouldn’t have any bearing on buffer names (that i can think of)
Is it not that CIDER infeers the host to connect to from the TRAMP connection settings ?
before we keep diagnosing. Can you confirm the following: • if you start up the project with a command CIDER works perfectly with cider-connect • if you edit the connection string CIDER uses (`C-u m-x cider-jack-in` and then edit the startup form) does it work correctly?
my TRAMP connection settings have "host = xxxx", but cider connect done by cider-jack-in
after having started the server on xxx should connect to "localhost".
as DEVPOD sets it up this way. It tunnels remote ports to "localhost", they are not existing at "xxxx:12345"
"starting the server" works.
but the second step of the cider-jack-in
(= doing a cider connect internally) fails.
as it tries alwaas to connect to "servername:port" and not "localhost:port"
In my case "servername:host" is not "exposed" only "localhost:port" is exposed.
so it does work to start the server via "ssh servername clojure ..." BUT the automatic "connect to servername:port" is not setup, it should use "localhost:port"
The log says this:
[nREPL] Starting server via /home/vscode/.asdf/shims/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.30.0"} refactor-nrepl/refactor-nrepl {:mvn/version "3.6.0"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"]}}}' -M:cider/nrepl
[nREPL] server started on 12345
[nREPL] Establishing direct connection to try-langchain-opencity.devpod:12345 ...
[nREPL] Direct connection to try-langchain-opencity.devpod:12345 failed
It would all work if CIDER would try (or could be configured) to "establish direct connection to localhost:12345"
instead of trying "Establishing direct connection to try-langchain-opencity.devpod:12345"
In case it helps, note there's https://github.com/clojure-emacs/cider/pull/3544 open
I know enabled the nrepl-use-ssh-fallback-for-remotes
(which might work, depending ho it does the tunnel ..)
But it gives error:
error in process filter: nrepl-connect: Wrong type argument: stringp, nil
May be the issue addressed by the pr above? https://github.com/clojure-emacs/cider/issues/3541
Inference from the tramp file name is not happening when the connection is made directly, only when made via ssh But yeah, this is broken at the moment. See the PR above.
You can try simplyfing the let bindings in nrepl--ssh-tunnel-connect
from
((current-buf (buffer-file-name))
(tramp-file-regexp "/ssh:\\(.+@\\)?\\(.+?\\)\\(:\\|#\\).+")
(remote-dir (cond
;; If current buffer is a TRAMP buffer and its host is
;; the same as HOST, reuse its connection parameters for
;; SSH tunnel.
((and (string-match tramp-file-regexp current-buf)
(string= host (match-string 2 current-buf))) current-buf)
;; Otherwise, if HOST was provided, use it for connection.
(host (format "/ssh:%s:" host))
;; Use default directory as fallback.
(t default-directory)))
(ssh (or (executable-find "ssh")
(error "[nREPL] Cannot locate 'ssh' executable")))
(cmd (nrepl--ssh-tunnel-command ssh remote-dir port))
(tunnel-buf (nrepl-tunnel-buffer-name
`((:host ,host) (:port ,port))))
(tunnel (start-process-shell-command "nrepl-tunnel" tunnel-buf cmd)))
to
((remote-dir nrepl-project-dir)
(ssh (or (executable-find "ssh")
(error "[nREPL] Cannot locate 'ssh' executable")))
(cmd (nrepl--ssh-tunnel-command ssh remote-dir port))
(tunnel-buf (nrepl-tunnel-buffer-name
`((:host ,host) (:port ,port))))
(tunnel (start-process-shell-command "nrepl-tunnel" tunnel-buf cmd)))
Regardless of ssh: when jacking in with clojure on a tramp remote, the host string is coming from https://github.com/clojure-emacs/cider/blob/95a19f09999d57d0c78d8a01795a455b6501e042/nrepl-client.el#L1186C34-L1186C34
(host (or (match-string 2 output)
(file-remote-p default-directory 'host)
"localhost"))
At the moment, this will always be (file-remote-p default-directory 'host)
see: https://github.com/clojure-emacs/cider/blob/95a19f09999d57d0c78d8a01795a455b6501e042/nrepl-client.el#L1130As I trey to debug this code, I see that I gon not get a "buffer-name" here: https://github.com/clojure-emacs/cider/blob/95a19f09999d57d0c78d8a01795a455b6501e042/nrepl-client.el#L590
(defun nrepl--ssh-tunnel-connect (host port)
"Connect to a remote machine identified by HOST and PORT through SSH tunnel."
(message "[nREPL] Establishing SSH tunneled connection to %s:%s ..." host port)
(message "current-buffer-2: %s" (current-buffer))
(message "buffer-name-2: %s" (buffer-name))
(message "buffer-file-name-2: %s" (buffer-file-name))
gives me:
current-buffer-2: *nrepl-server workspaces/try-langchain-opencity:localhost*-263499
buffer-name-2: *nrepl-server workspaces/try-langchain-opencity:localhost*-263499
buffer-file-name-2: nil
I am only having the TRAMP buffer with a Clojure file open when running the cider-jack-in
How can this be ???
So how can the current buffer be "not my Clojure file ..."Because the execution context of this is the nrepl buffer.
ahhh. OK, I see. So we do not infeere from buffer filename, but from nrepl-buffer name (whcih has teh same information . But is is nil... buffer-file-name-2: nil
(buffer-name) is not nil, but current CIDER code uses (buffer-file-name) which is nil (at least in my case)
so for me the "parsing" breaks in the beginning alreday
See what I've written above about changing the let-binding in nrepl--ssh-tunnel-connect
. I'd expect that to work, because
nrepl-project-dir
is a local that should be available in that context and contain the tramp file-name of the project root.
and additional the regexp in current CIDER code looks for "/ssh..." which is the format of the "file-name" not name of the nrepl-buffer...
Yeah, forget the cond, it will be gone soon.
I use "current" cider, not your fork.
So for me it "looks like" the function
(defun nrepl--ssh-tunnel-connect (host port)
is not only "not taking all cases", but it does not work at all in my setup , because it tries to operate on (buffer-file-name)
to detect something , which is "nil" for me...Aye, don't use the fork, it's overcomplicated and fixes only the cider-jack-in-clj path. Current cider does this:
(remote-dir (cond
;; false in both scenarios (jack-in and connect), because current-buf is the nrepl buffer
((and (string-match tramp-file-regexp current-buf)
(string= host (match-string 2 current-buf))) current-buf)
;; true in both scenarios, because host is always passed as an arg [?]
(host (format "/ssh:%s:" host))
;; never hit
(t default-directory)))
.... with host
being passed down as (file-remote-p default-directory 'host)
, like mentioned above.
EDIT: To clarify, this might just become:
(remote-dir nrepl-project-dir)
host
tracing back to (file-remote-p default-directory 'host)
is only true for jack-in and not taking sessions, bb and .dir-locals
into account. On the connect route host
is coming from cider--update-host-port
, either
- passed down as :host
in params
from the top level function
- or the user will get be prompted
I'm still figuring out the big picture and how everything is connected but am a bit short on time. I expect to have an answer on how to solve this properly by the end of the week. Feel free to join the dig :)
my nil related problem is tracked here: https://github.com/clojure-emacs/cider/pull/3544
I will wait for a fix for this, in order to further check if in my precise scenario I can use cider-jack-in
or not
I think that a "rather simple" solution for getting "jack-in" type of behaviour working in more scenarios is to add an alternative cider-start-server
function to CIDER, which starts the server only, but does not try to connect afterwards.
(so we assume that the users runs cider-connect
afterwards and knows host and port)
Somehow my conclusion from previous discussion is, that to deduct "host and port" to connect to from the "server start commands and observing buffer names and looking for .nrepl-port files will never be 100 % perfect.
A local ssh configuration or other "TCP" setups or other "networking tricks" cannot be discovered by CIDER,
This works with existing code, passing nil as the ON-PORT-CALLBACK
:
(nrepl-start-server-process
(plist-get params :project-dir)
(plist-get params :jack-in-cmd)
nil)