Skip to content

Commit 0f4887b

Browse files
danmidwoodbbatsov
authored andcommitted
Locate multiple ports for a single project
Searching for a nrepl port to connect to would return a maximum of one port per project, ignoring any others that you might want to connect to. This creates a case where when connecting to a shadow-cljs nrepl server the port is not presented to you as a completion when you already have another nrepl server running. This commit changes nrepl-extract-port to nrepl-extract-ports and the return type from a single port to a list of ports (including nils where a specific project type nrepl port file doesn't exist) to provide the full view of nrepl servers that are available in the project, and then the cider-locate-running-nrepl-ports fn is changed to accommodate that. This fixes #3140.
1 parent 8da628c commit 0f4887b

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
### Bugs fixed
2121

2222
* [#3235](https://github.com/clojure-emacs/cider/issues/3235): Check `name` is a TRAMP file in `cider--client-tramp-filename` via `tramp-tramp-file-p`.
23+
- [#3234](https://github.com/clojure-emacs/cider/pull/3234) Autocomplete multiple available ports on nRepl connect.
2324

2425
## 1.4.1 (2022-05-25)
2526

cider.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,11 @@ of remote SSH hosts."
16251625
When DIR is non-nil also look for nREPL port files in DIR. Return a list
16261626
of list of the form (project-dir port)."
16271627
(let* ((paths (cider--running-nrepl-paths))
1628-
(proj-ports (mapcar (lambda (d)
1629-
(when-let* ((port (and d (nrepl-extract-port (cider--file-path d)))))
1630-
(list (file-name-nondirectory (directory-file-name d)) port)))
1631-
(cons (clojure-project-dir dir) paths))))
1628+
(proj-ports (apply #'append
1629+
(mapcar (lambda (d)
1630+
(mapcar (lambda (p) (list (file-name-nondirectory (directory-file-name d)) p))
1631+
(and d (nrepl-extract-ports (cider--file-path d)))))
1632+
(cons (clojure-project-dir dir) paths)))))
16321633
(seq-uniq (delq nil proj-ports))))
16331634

16341635
(defun cider--running-nrepl-paths ()

nrepl-client.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ PARAMS is as in `nrepl-make-buffer-name'."
237237
(nrepl--port-from-file (expand-file-name "target/repl-port" dir))
238238
(nrepl--port-from-file (expand-file-name ".shadow-cljs/nrepl.port" dir))))
239239

240+
(defun nrepl-extract-ports (dir)
241+
"Read ports from applicable repl-port files in directory DIR."
242+
(delq nil
243+
(list (nrepl--port-from-file (expand-file-name "repl-port" dir))
244+
(nrepl--port-from-file (expand-file-name ".nrepl-port" dir))
245+
(nrepl--port-from-file (expand-file-name "target/repl-port" dir))
246+
(nrepl--port-from-file (expand-file-name ".shadow-cljs/nrepl.port" dir)))))
247+
248+
(make-obsolete 'nrepl-extract-port 'nrepl-extract-ports "1.4.2")
249+
240250
(defun nrepl--port-from-file (file)
241251
"Attempts to read port from a file named by FILE."
242252
(when (file-exists-p file)

0 commit comments

Comments
 (0)