[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/cider c37fb4566c 2/2: Fix `cider-jack-in` failing in remot
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/cider c37fb4566c 2/2: Fix `cider-jack-in` failing in remote ssh buffers (#3544) |
Date: |
Mon, 30 Oct 2023 19:00:36 -0400 (EDT) |
branch: elpa/cider
commit c37fb4566c137300ac6ef2f729b15bf6eb066f4f
Author: adrech <33599806+adrech@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
Fix `cider-jack-in` failing in remote ssh buffers (#3544)
* tramp-sample-project: fix Lein not finding `java` after cider-jack-in
This is a workaround that can be removed when `PATH` is picked up
correctly when jacking in on the running remote.
Circumvents:
```
Tramp: Opening connection nrepl-server for root@localhost using sshx...done
[nREPL] Starting server via lein update-in :dependencies conj
\[nrepl/nrepl\ \"1.0.0\"\] -- update-in :plugins conj \[cider/cider-nrepl\
\"0.40.0\"\] -- repl :headless :host localhost
error in process sentinel: let: Could not start nREPL server:
/usr/local/bin/lein: line 224: type: java: not found
Leiningen couldn't find 'java' executable, which is required.
Please either set JAVA_CMD or put java (>=1.6) in your $PATH
(/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin).
("exited abnormally with code 1")
```
* tramp-sample-project: add `cider-jack-in` method to README
* Fix `cider-jack-in` failing with SSH remotes
Calling cider-jack-in from a tramp buffer on a ssh-remote would throw:
"error in process filter: Wrong type argument: stringp, nil"
This happens because nrepl--ssh-tunnel-connect is trying to infer the
hostname from the current filename: It string-matches
on (buffer-file-name) which returns nil in
the *cider-uninitialized-repl* buffer.
For the jack-in use-case, the local var nrepl-project-dir will
always be bound when connecting the client, so we can use
it as a fallback.
Fixes https://github.com/clojure-emacs/cider/issues/3541
---
CHANGELOG.md | 1 +
dev/tramp-sample-project/Dockerfile | 1 +
dev/tramp-sample-project/README.md | 9 ++++++++-
nrepl-client.el | 12 ++++++++----
test/nrepl-client-tests.el | 21 +++++++++++++++++++++
5 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cfa114d42e..938be21ac6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@
### Bugs fixed
+- [#3541](https://github.com/clojure-emacs/cider/issues/3541): Fix
`cider-jack-in` failing with SSH remotes.
- [#3559](https://github.com/clojure-emacs/cider/issues/3559): Don't apply
[dynamic syntax
highlighting](https://docs.cider.mx/cider/config/syntax_highlighting.html) over
buffers belonging to unrelated Sesman sessions.
## 1.9.0 (2023-10-24)
diff --git a/dev/tramp-sample-project/Dockerfile
b/dev/tramp-sample-project/Dockerfile
index 7f9c06c2a7..7d87b18cdc 100644
--- a/dev/tramp-sample-project/Dockerfile
+++ b/dev/tramp-sample-project/Dockerfile
@@ -36,6 +36,7 @@ COPY . /usr/src/app
RUN lein deps
RUN echo "export JAVA_HOME=${JAVA_HOME}" >> /root/.bashrc
+RUN echo "export JAVA_CMD=${JAVA_HOME}/bin/java" >> /root/.bashrc
RUN echo "export LEIN_HOME=${LEIN_HOME}" >> /root/.bashrc
RUN echo "export LEIN_JAVA_CMD=${LEIN_JAVA_CMD}" >> /root/.bashrc
RUN echo "export LEIN_JVM_OPTS=${LEIN_JVM_OPTS}" >> /root/.bashrc
diff --git a/dev/tramp-sample-project/README.md
b/dev/tramp-sample-project/README.md
index e6ab911ff4..b913ea37c4 100644
--- a/dev/tramp-sample-project/README.md
+++ b/dev/tramp-sample-project/README.md
@@ -4,8 +4,15 @@ The Docker image exposes a SSH server.
This way, for development purposes, we can SSH into it with TRAMP and exercise
CIDER's TRAMP-related capabilities.
-To get started:
+## Some ways to get started:
+### `cider-jack-in` from a tramp buffer
+* `M-:` `(async-shell-command "make run")` to run the Docker image
+* `M-:` `(find-file "/sshx:root@localhost#8022:/usr/src/app/src/foo.clj")`
+* `M-x` `cider-jack-in`
+* Enter password: `cider`
+
+### Manually create a remote repl and connect to it
* In one terminal tab, run `make run` to run the Docker image
* Once it's ready, from another tab, run `make ssh` and start a repl manually
from there
* The password is `cider`
diff --git a/nrepl-client.el b/nrepl-client.el
index 43b9759232..81bca0ef27 100644
--- a/nrepl-client.el
+++ b/nrepl-client.el
@@ -271,6 +271,12 @@ Discards it if it can be determined that the port is not
active."
(shell-command-to-string (format "lsof -i:%s"
port-number))))
port-string)))))
+(defun nrepl--ssh-file-name-matches-host-p (file-name host)
+ "Return t, if FILE-NAME is a tramp-file-name on HOST via ssh."
+ (when (tramp-tramp-file-p file-name)
+ (with-parsed-tramp-file-name file-name v
+ (and (member v-method '("ssh" "sshx"))
+ (member host (list v-host (concat v-host "#" v-port)))))))
;;; Bencode
@@ -587,14 +593,12 @@ If NO-ERROR is non-nil, show messages instead of throwing
an error."
(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)
- (let* ((current-buf (buffer-file-name))
- (tramp-file-regexp "/ssh:\\(.+@\\)?\\(.+?\\)\\(:\\|#\\).+")
+ (let* ((file-name (or (buffer-file-name) nrepl-project-dir))
(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)
+ ((nrepl--ssh-file-name-matches-host-p file-name host)
file-name)
;; Otherwise, if HOST was provided, use it for
connection.
(host (format "/ssh:%s:" host))
;; Use default directory as fallback.
diff --git a/test/nrepl-client-tests.el b/test/nrepl-client-tests.el
index cf4e23e86d..bb5775eb4d 100644
--- a/test/nrepl-client-tests.el
+++ b/test/nrepl-client-tests.el
@@ -158,6 +158,27 @@
(expect (match-string 1 msg)
:to-equal "nrepl.sock"))))
+(describe "nrepl--ssh-file-name-matches-host-p"
+ (it "works in the most basic case"
+ (expect (nrepl--ssh-file-name-matches-host-p "/ssh:host:~/test/" "host")
+ :to-be-truthy)
+ (expect (nrepl--ssh-file-name-matches-host-p "/ssh:host:~/test/"
"other-host")
+ :to-be nil))
+ (it "understands non-standart ssh ports and distinguishes between them"
+ (expect (nrepl--ssh-file-name-matches-host-p
+ "/ssh:tester@host#8022:~/test/" "host#8022")
+ :to-be-truthy)
+ (expect (nrepl--ssh-file-name-matches-host-p
+ "/ssh:tester@host#8022:~/test/" "host#7777")
+ :to-be nil))
+ (it "works with tramps other ssh methods"
+ (expect (nrepl--ssh-file-name-matches-host-p
+ "/sshx:tester@host:~/test/" "host")
+ :to-be-truthy))
+ (it "can handle nil"
+ (expect (nrepl--ssh-file-name-matches-host-p nil nil)
+ :to-be nil)))
+
(describe "nrepl-client-lifecycle"
(it "start and stop nrepl client process"