From 315494a6655334500f68bace75c2c0a684c2a4bf Mon Sep 17 00:00:00 2001 From: vemv Date: Tue, 17 Oct 2023 22:13:39 +0200 Subject: [PATCH] Refine Sesman session linking to accurately work on `*cider-test-report*` buffers Fixes #3533 --- CHANGELOG.md | 4 ++++ cider-repl.el | 23 ++++++++++++++++++----- cider-test.el | 9 ++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c986919fd..460df6fca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bugs fixed + +- [#3533](https://github.com/clojure-emacs/cider/issues/3533): Refine Sesman session linking to accurately work on `*cider-test-report*` buffers. + ### Changes - [#3521](https://github.com/clojure-emacs/cider/issues/3521): Expand `cider-clojure-compilation-regexp` to also match e.g. `Unexpected error (ExceptionInfo) macroexpanding defmulti at (src/ns.clj:1:1).`. diff --git a/cider-repl.el b/cider-repl.el index 85ef19c63..6499e9f0a 100644 --- a/cider-repl.el +++ b/cider-repl.el @@ -1762,16 +1762,29 @@ constructs." The checking is done as follows: -* Consider if the buffer belongs to `cider-ancillary-buffers` +* If the current buffer's name equals to the value of `cider-test-report-buffer', + only accept the given session's repl if it equals `cider-test--current-repl' +* Consider if the buffer belongs to `cider-ancillary-buffers' * Consider the buffer's filename, strip any Docker/TRAMP details from it * Check if that filename belongs to the classpath, or to the classpath roots (e.g. the project root dir) * As a fallback, check if the buffer's ns form matches any of the loaded namespaces." (setcdr session (seq-filter #'buffer-live-p (cdr session))) - (or (member (buffer-name) cider-ancillary-buffers) - (when-let* ((repl (cadr session)) - (proc (get-buffer-process repl)) + (when-let ((repl (cadr session))) + (cond + ((equal (buffer-name) + cider-test-report-buffer) + (or (not cider-test--current-repl) + (not (buffer-live-p cider-test--current-repl)) + (equal repl + cider-test--current-repl))) + + ((member (buffer-name) cider-ancillary-buffers) + t) + + (t + (when-let* ((proc (get-buffer-process repl)) (file (file-truename (or (buffer-file-name) default-directory)))) ;; With avfs paths look like /path/to/.avfs/path/to/some.jar#uzip/path/to/file.clj (when (string-match-p "#uzip" file) @@ -1826,7 +1839,7 @@ The checking is done as follows: (member ns (nrepl-dict-keys cider-repl-ns-cache))) (member ns ns-list)))) (when debug - (list file "was not determined to belong to classpath:" classpath "or classpath-roots:" classpath-roots)))))))) + (list file "was not determined to belong to classpath:" classpath "or classpath-roots:" classpath-roots)))))))))) (defun cider-debug-sesman-friendly-session-p () "`message's debugging information relative to friendly sessions. diff --git a/cider-test.el b/cider-test.el index e80ab6d3c..c80310030 100644 --- a/cider-test.el +++ b/cider-test.el @@ -62,6 +62,11 @@ (make-obsolete 'cider-test-defining-forms nil "1.8.0") +(defvar cider-test--current-repl nil + "Contains the reference to the REPL where the tests were last invoked from. +This is needed for *cider-test-report* navigation +to work against the correct REPL session.") + (defvar cider-test-last-summary nil "The summary of the last run test.") @@ -289,7 +294,8 @@ prompt and whether to use a new window. Similar to `cider-find-var'." cider-auto-select-error-buffer #'cider-stacktrace-mode 'ancillary) - (reverse causes)))))))))) + (reverse causes))))))) + cider-test--current-repl))) (defun cider-test-stacktrace () "Display stacktrace for the erring test at point." @@ -710,6 +716,7 @@ running them." ;; we generate a different message when running individual tests (cider-test-echo-running ns (car tests)) (cider-test-echo-running ns))) + (setq cider-test--current-repl conn) (let* ((retest? (eq :non-passing ns)) (request `("op" ,(cond ((stringp ns) "test") ((eq :project ns) "test-all")