Fork me on GitHub
#cider
<
2023-10-25
>
vemv05:10:35

ℹ️ 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 👀

🎉 6
danielneal08:10:46

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.

vemv08:10:18

> 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!

danielneal09:10:28

Thanks!!!

🙌 1
Carsten Behring13:10:06

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 ?

dpsutton13:10:52

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

Carsten Behring13:10:33

yes, that does work So I manged to start the nrepl server on a fixed port.

dpsutton13:10:14

does that completely solve your problem?

Carsten Behring13:10:38

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

Carsten Behring13:10:33

So basically I would need a "fallback-to-localhost".....

Carsten Behring13:10:09

I agree, I have an unsual setup. (but it is the default setup when using "devpod" (https://devpod.sh/)

dpsutton13:10:09

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.

dpsutton13:10:47

also confused why tramp is involved in editing files

Carsten Behring13:10:21

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,

dpsutton13:10:50

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

Carsten Behring13:10:27

Yes, I agree. I came to that conclusion as well.

Carsten Behring13:10:52

But I was investigating if I can use teh "compfort" of cider-jack-in as well for my setup.

dpsutton13:10:02

so does everything work correctly if you start your project and nrepl in a terminal and connecting from CIDER?

dpsutton13:10:20

oh that’s annoying.

Carsten Behring13:10:22

cider-jack-in and its configuration options do not handle "all cases", mine is not handled / configurable.

dpsutton13:10:39

i guess i’m not clear which axis missing

dpsutton13:10:19

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

Carsten Behring13:10:39

That the relationship between "emacs buffer name having a host name in case of TRAMP" could still mean "connect to localhost"

dpsutton13:10:57

i don’t follow that

dpsutton14:10:19

if you can correctly cider-connect to a startup form, can you edit the jack-in startup form and have a working setup?

Carsten Behring14:10:19

my buffer says "xxx.clj@a-host`

dpsutton14:10:42

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

dpsutton14:10:59

and cider-jack-in or cider-connect shouldn’t have any bearing on buffer names (that i can think of)

Carsten Behring14:10:40

Is it not that CIDER infeers the host to connect to from the TRAMP connection settings ?

dpsutton14:10:03

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?

Carsten Behring14:10:14

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".

Carsten Behring14:10:59

as DEVPOD sets it up this way. It tunnels remote ports to "localhost", they are not existing at "xxxx:12345"

Carsten Behring14:10:28

"starting the server" works. but the second step of the cider-jack-in (= doing a cider connect internally) fails.

Carsten Behring14:10:20

as it tries alwaas to connect to "servername:port" and not "localhost:port"

Carsten Behring14:10:46

In my case "servername:host" is not "exposed" only "localhost:port" is exposed.

Carsten Behring14:10:29

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"

Carsten Behring14:10:12

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

Carsten Behring14:10:17

It would all work if CIDER would try (or could be configured) to "establish direct connection to localhost:12345"

Carsten Behring14:10:35

instead of trying "Establishing direct connection to try-langchain-opencity.devpod:12345"

Carsten Behring14:10:16

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

vemv14:10:12

May be the issue addressed by the pr above? https://github.com/clojure-emacs/cider/issues/3541

Karl Xaver14:10:15

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.

Karl Xaver14:10:23

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)))

Karl Xaver15:10:00

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#L1130

Carsten Behring15:10:32

As 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 ..."

Karl Xaver15:10:48

Because the execution context of this is the nrepl buffer.

Carsten Behring15:10:11

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

Carsten Behring15:10:00

(buffer-name) is not nil, but current CIDER code uses (buffer-file-name) which is nil (at least in my case)

Carsten Behring15:10:08

so for me the "parsing" breaks in the beginning alreday

Karl Xaver15:10:24

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.

Carsten Behring15:10:40

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...

Karl Xaver15:10:07

Yeah, forget the cond, it will be gone soon.

Carsten Behring15:10:33

I use "current" cider, not your fork.

Carsten Behring15:10:10

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...

Karl Xaver15:10:08

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)

Karl Xaver15:10:02

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

Karl Xaver15:10:45

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 :)

Carsten Behring19:10:06

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

Carsten Behring21:10:52

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)

vemv21:10:59

Roughly speaking, a PR that split a defun into two defuns would be welcome 🙂