branch: elpa/cider
commit aa23b251b12cee69d8db1933103107369fcdc337
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    Add a cider-doctor-mode with g-to-refresh
    
    Give the report buffer its own major mode (derived from special-mode) so
    the checks can be re-run in place with `g` after fixing something, rather
    than invoking M-x cider-doctor again. Rendering moves into a reusable
    helper wired up as the buffer's revert-buffer-function.
---
 doc/modules/ROOT/pages/troubleshooting.adoc |  3 +++
 lisp/cider-doctor.el                        | 42 +++++++++++++++++++++--------
 test/cider-doctor-tests.el                  | 19 +++++++++++++
 3 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/doc/modules/ROOT/pages/troubleshooting.adoc 
b/doc/modules/ROOT/pages/troubleshooting.adoc
index 0be23b8826..79a82ed61f 100644
--- a/doc/modules/ROOT/pages/troubleshooting.adoc
+++ b/doc/modules/ROOT/pages/troubleshooting.adoc
@@ -26,6 +26,9 @@ nREPL, `cider-nrepl` and Clojure versions and probes the 
middleware ops
 that back the major features - so a missing feature shows up as a named
 missing op rather than a mystery.
 
+Press kbd:[g] in the report buffer to re-run the checks in place, for
+instance after installing a missing dependency or starting a REPL.
+
 TIP: The report is meant to be copied into a bug report, which usually saves a
 round of back-and-forth about your environment.
 
diff --git a/lisp/cider-doctor.el b/lisp/cider-doctor.el
index ab27a420b9..c196cf5c74 100644
--- a/lisp/cider-doctor.el
+++ b/lisp/cider-doctor.el
@@ -302,24 +302,44 @@ detail names the affected feature."
   (mapc #'cider-doctor--insert-result results)
   (insert "\n"))
 
+(defun cider-doctor--render ()
+  "Render the diagnostics report into the current buffer.
+Runs the offline environment checks and, when a REPL is connected, the
+connection-health checks."
+  (let ((inhibit-read-only t))
+    (erase-buffer)
+    (insert "CIDER Doctor\n")
+    (insert "============\n\n")
+    (cider-doctor--insert-section "Environment" (cider-doctor--offline-checks))
+    (if (cider-doctor--online-p)
+        (cider-doctor--insert-section "Connection" 
(cider-doctor--online-checks))
+      (insert "Connection\n\nNo active REPL; connection checks skipped.\n\n"))
+    (goto-char (point-min))))
+
+(defun cider-doctor--revert (&rest _)
+  "Re-run the checks and re-render the report.
+Serves as the `revert-buffer-function', so \\[revert-buffer] refreshes the
+report in place."
+  (cider-doctor--render))
+
+(define-derived-mode cider-doctor-mode special-mode "CIDER Doctor"
+  "Major mode for the CIDER Doctor report.
+Press \\[revert-buffer] to re-run the checks and refresh the report.
+
+\\{cider-doctor-mode-map}"
+  (setq-local revert-buffer-function #'cider-doctor--revert))
+
 ;;;###autoload
 (defun cider-doctor ()
   "Diagnose the current CIDER setup and show a report.
 Runs offline environment checks and, when a REPL is connected, a set of
 connection-health checks.  The resulting buffer is meant to be pasted
-into bug reports."
+into bug reports.  Press \\<cider-doctor-mode-map>\\[revert-buffer] to
+refresh it."
   (interactive)
-  (let ((buffer (cider-popup-buffer "*cider-doctor*" 'select)))
+  (let ((buffer (cider-popup-buffer "*cider-doctor*" 'select 
#'cider-doctor-mode)))
     (with-current-buffer buffer
-      (let ((inhibit-read-only t))
-        (erase-buffer)
-        (insert "CIDER Doctor\n")
-        (insert "============\n\n")
-        (cider-doctor--insert-section "Environment" 
(cider-doctor--offline-checks))
-        (if (cider-doctor--online-p)
-            (cider-doctor--insert-section "Connection" 
(cider-doctor--online-checks))
-          (insert "Connection\n\nNo active REPL; connection checks 
skipped.\n\n"))
-        (goto-char (point-min))))
+      (cider-doctor--render))
     buffer))
 
 ;;; Helpers
diff --git a/test/cider-doctor-tests.el b/test/cider-doctor-tests.el
index ab78261545..0ea58a3de6 100644
--- a/test/cider-doctor-tests.el
+++ b/test/cider-doctor-tests.el
@@ -171,6 +171,25 @@
       (expect (plist-get result :status) :to-be 'warn)
       (expect (plist-get result :detail) :to-match "xref"))))
 
+(describe "cider-doctor"
+  (after-each
+    (when (get-buffer "*cider-doctor*")
+      (kill-buffer "*cider-doctor*")))
+
+  (it "renders into a cider-doctor-mode buffer"
+    (with-current-buffer (cider-doctor)
+      (expect major-mode :to-be 'cider-doctor-mode)
+      (expect (buffer-substring-no-properties (point-min) (min 13 (point-max)))
+              :to-equal "CIDER Doctor")))
+
+  (it "refreshes in place via revert-buffer"
+    (with-current-buffer (cider-doctor)
+      (expect revert-buffer-function :to-be #'cider-doctor--revert)
+      ;; a revert re-runs the checks without erroring and keeps the report
+      (revert-buffer)
+      (expect (buffer-substring-no-properties (point-min) (min 13 (point-max)))
+              :to-equal "CIDER Doctor"))))
+
 (provide 'cider-doctor-tests)
 
 ;;; cider-doctor-tests.el ends here

Reply via email to