Skip to content

Commit

Permalink
Locate multiple ports for a single project
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danmidwood authored and bbatsov committed Aug 10, 2022
1 parent 8da628c commit 0f4887b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Bugs fixed

* [#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`.
- [#3234](https://github.com/clojure-emacs/cider/pull/3234) Autocomplete multiple available ports on nRepl connect.

## 1.4.1 (2022-05-25)

Expand Down
9 changes: 5 additions & 4 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,11 @@ of remote SSH hosts."
When DIR is non-nil also look for nREPL port files in DIR. Return a list
of list of the form (project-dir port)."
(let* ((paths (cider--running-nrepl-paths))
(proj-ports (mapcar (lambda (d)
(when-let* ((port (and d (nrepl-extract-port (cider--file-path d)))))
(list (file-name-nondirectory (directory-file-name d)) port)))
(cons (clojure-project-dir dir) paths))))
(proj-ports (apply #'append
(mapcar (lambda (d)
(mapcar (lambda (p) (list (file-name-nondirectory (directory-file-name d)) p))
(and d (nrepl-extract-ports (cider--file-path d)))))
(cons (clojure-project-dir dir) paths)))))
(seq-uniq (delq nil proj-ports))))

(defun cider--running-nrepl-paths ()
Expand Down
10 changes: 10 additions & 0 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ PARAMS is as in `nrepl-make-buffer-name'."
(nrepl--port-from-file (expand-file-name "target/repl-port" dir))
(nrepl--port-from-file (expand-file-name ".shadow-cljs/nrepl.port" dir))))

(defun nrepl-extract-ports (dir)
"Read ports from applicable repl-port files in directory DIR."
(delq nil
(list (nrepl--port-from-file (expand-file-name "repl-port" dir))
(nrepl--port-from-file (expand-file-name ".nrepl-port" dir))
(nrepl--port-from-file (expand-file-name "target/repl-port" dir))
(nrepl--port-from-file (expand-file-name ".shadow-cljs/nrepl.port" dir)))))

(make-obsolete 'nrepl-extract-port 'nrepl-extract-ports "1.4.2")

(defun nrepl--port-from-file (file)
"Attempts to read port from a file named by FILE."
(when (file-exists-p file)
Expand Down

0 comments on commit 0f4887b

Please sign in to comment.