diff --git a/CHANGELOG.md b/CHANGELOG.md index d4c8cfcd4..59eae781f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/nrepl-client.el b/nrepl-client.el index 97be8e0f8..23dbbf6a2 100644 --- a/nrepl-client.el +++ b/nrepl-client.el @@ -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