Skip to content

Commit 2cce721

Browse files
committed
Merge pull request #1156 from vspinu/1142
[Fix #1142] Don't sniff for ports when port is present in cider-known-endpoint
2 parents eabd952 + 5f34683 commit 2cce721

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Bugs fixed
66

7+
* [#1142](https://github.com/clojure-emacs/cider/issues/1142): Don't retrive nrepl ports when `cider-known-endpoints` entry already contains the port.
78
* [#1153](https://github.com/clojure-emacs/cider/pull/1153): Fix behavior of `cider-switch-to-current-repl-buffer`.
89
* [#1139](https://github.com/clojure-emacs/cider/issues/1139): Fix evaluation of ns forms and of forms with unevaluated namespaces.
910
* Replace `assert` with `cl-assert` (we don't use anything from `cl` now).

cider.el

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ Create REPL buffer and start an nREPL client connection."
212212
"Interactively select the host and port to connect to."
213213
(let* ((ssh-hosts (cider--ssh-hosts))
214214
(hosts (-distinct (append (when cider-host-history
215-
(list (list (car cider-host-history))))
215+
;; history elements are strings of the form "host:port"
216+
(list (split-string (car cider-host-history) ":")))
216217
(list (list (nrepl-current-host)))
217218
cider-known-endpoints
218219
ssh-hosts
@@ -221,24 +222,8 @@ Create REPL buffer and start an nREPL client connection."
221222
(list (list "localhost"))))))
222223
(sel-host (cider--completing-read-host hosts))
223224
(host (car sel-host))
224-
(local-p (or (nrepl-local-host-p host)
225-
(not (assoc-string host ssh-hosts))))
226-
;; Each lein-port is a list of the form (dir port)
227-
(lein-ports (if local-p
228-
;; might connect to localhost from a remote file
229-
(let* ((change-dir-p (file-remote-p default-directory))
230-
(default-directory (if change-dir-p "~/" default-directory)))
231-
(cider-locate-running-nrepl-ports (unless change-dir-p default-directory)))
232-
(let ((vec (vector "sshx" nil host "" nil))
233-
;; might connect to a different remote
234-
(dir (when (file-remote-p default-directory)
235-
(with-parsed-tramp-file-name default-directory cur
236-
(when (string= cur-host host) default-directory)))))
237-
(tramp-maybe-open-connection vec)
238-
(with-current-buffer (tramp-get-connection-buffer vec)
239-
(cider-locate-running-nrepl-ports dir)))))
240-
(ports (append (cdr sel-host) lein-ports))
241-
(port (cider--completing-read-port host ports)))
225+
(port (or (cadr sel-host)
226+
(cider--completing-read-port host (cider--infer-ports host ssh-hosts)))))
242227
(list host port)))
243228

244229
(defun cider--ssh-hosts ()
@@ -258,6 +243,26 @@ Return a list of the form (HOST PORT), where PORT can be nil."
258243
;; remove the label
259244
(if (= 3 (length host)) (cdr host) host)))
260245

246+
(defun cider--infer-ports (host ssh-hosts)
247+
"Infer nREPL ports on HOST.
248+
Return a list of elements of the form (directory port). SSH-HOSTS is a list
249+
of remote SSH hosts."
250+
(let ((localp (or (nrepl-local-host-p host)
251+
(not (assoc-string host ssh-hosts)))))
252+
(if localp
253+
;; change dir: current file might be remote
254+
(let* ((change-dir-p (file-remote-p default-directory))
255+
(default-directory (if change-dir-p "~/" default-directory)))
256+
(cider-locate-running-nrepl-ports (unless change-dir-p default-directory)))
257+
(let ((vec (vector "sshx" nil host "" nil))
258+
;; change dir: user might want to connect to a different remote
259+
(dir (when (file-remote-p default-directory)
260+
(with-parsed-tramp-file-name default-directory cur
261+
(when (string= cur-host host) default-directory)))))
262+
(tramp-maybe-open-connection vec)
263+
(with-current-buffer (tramp-get-connection-buffer vec)
264+
(cider-locate-running-nrepl-ports dir))))))
265+
261266
(defun cider--completing-read-port (host ports)
262267
"Interactively select port for HOST from PORTS."
263268
(let* ((ports (cider-join-into-alist ports))

0 commit comments

Comments
 (0)