Skip to content

Commit

Permalink
Check .nrepl-port-like files for liveness
Browse files Browse the repository at this point in the history
Fixes #3408
  • Loading branch information
vemv committed Aug 14, 2023
1 parent 4a35e24 commit 7b282bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
### Changes

- [#3390](https://github.com/clojure-emacs/cider/issues/3390): Enhance `cider-connect` to show all nREPLs available ports, instead of only Leiningen ones.
- [#3408](https://github.com/clojure-emacs/cider/issues/3408): `cider-connect`: check `.nrepl-port`-like files for liveness, hiding them if they don't reflect an active port.
- Preserve the `:cljs-repl-type` more reliably.
- Improve the presentation of `xref` data.
- `cider-test`: only show diffs for collections.
Expand Down
16 changes: 11 additions & 5 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,18 @@ PARAMS is as in `nrepl-make-buffer-name'."
(make-obsolete 'nrepl-extract-port 'nrepl-extract-ports "1.5.0")

(defun nrepl--port-from-file (file)
"Attempts to read port from a file named by FILE."
"Attempts to read port from a file named by FILE.
Discards it if it can be determined that the port is not active."
(when (file-exists-p file)
(with-temp-buffer
(insert-file-contents file)
(replace-regexp-in-string "\n\\'" "" ;; remove any trailing newline, so that our UIs look better.
(buffer-string)))))
(let ((port-string (with-temp-buffer
(insert-file-contents file)
(string-trim-right (buffer-string)))))
(if (eq system-type 'windows-nt)
port-string
(when (not (equal ""
(shell-command-to-string (concat "lsof -i:" port-string))))
port-string)))))


;;; Bencode
Expand Down

0 comments on commit 7b282bf

Please sign in to comment.