Skip to content

Commit ec0ba20

Browse files
committed
Fix the rough edges the branch review found in the new views
Refreshing a query whose calls disappeared (log cleared, workspace reset) now renders the emptied view with a hint instead of erroring over stale content. The auto-refresh of a visible traced view keeps its namespace filter. The tree's pretty-print no longer resets point in the tree buffer. The empty-state hints look their key sequences up live instead of hardcoding C-c s, so custom prefixes show correctly. Also merges the accidentally duplicated Changes heading in the changelog.
1 parent d438bce commit ec0ba20

3 files changed

Lines changed: 107 additions & 48 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* Rename the per-function trace commands for consistency: `sayid-trace-fn-outer`, `sayid-trace-fn-inner` and `sayid-trace-fn-remove` (the old `sayid-outer-trace-fn`, `sayid-inner-trace-fn` and `sayid-remove-trace-fn` names remain as obsolete aliases).
1515
* Bring the workspace tree view to feature parity with the legacy text view: `c d` defs a captured value to `$s/*`, `c p` pretty-prints one, and `c r` copies an expression reproducing the call at point.
1616
* `sayid-query-form-at-point` (`C-c s f`) now renders its results in the tree view, backed by the new `sayid-query-form-at-point-data` op, instead of the legacy text view.
17-
18-
### Changes
19-
2017
* Require CIDER 2.0.
2118

2219
### Bugs fixed

‎src/el/sayid.el‎

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,12 @@ state. POS is the position to move cursor to."
316316

317317
(defun sayid-tree--show-form-query (file line)
318318
"Fetch and render every recorded call of the form at FILE and LINE as a tree."
319-
(let ((roots (sayid-req-get-value (list "op" "sayid-query-form-at-point-data"
320-
"file" file
321-
"line" line))))
322-
(if roots
323-
(sayid-tree--render roots
324-
(format "Query: %s:%s"
325-
(file-name-nondirectory file) line)
326-
nil
327-
(lambda () (sayid-tree--show-form-query file line)))
328-
(user-error "No recorded calls for the form at point"))))
319+
(sayid-tree--show-query
320+
(lambda () (sayid-req-get-value (list "op" "sayid-query-form-at-point-data"
321+
"file" file
322+
"line" line)))
323+
(format "Query: %s:%s" (file-name-nondirectory file) line)
324+
"No recorded calls for the form at point"))
329325

330326
;;;###autoload
331327
(defun sayid-query-form-at-point ()
@@ -363,9 +359,12 @@ to naming the command."
363359
(t (format "M-x %s" command)))))
364360

365361
(defun sayid--refresh-traced-if-visible ()
366-
"Refresh the traced-functions view when its buffer is visible."
367-
(when (get-buffer-window "*sayid-traced*" 'visible)
368-
(save-selected-window (sayid-show-traced))))
362+
"Refresh the traced-functions view when its buffer is visible.
363+
Preserves the namespace filter the view was rendered with."
364+
(when-let* ((win (get-buffer-window "*sayid-traced*" 'visible)))
365+
(save-selected-window
366+
(sayid-show-traced
367+
(buffer-local-value 'sayid-traced--ns (window-buffer win))))))
369368

370369
(defun sayid--trace-fn-at-point (action)
371370
"Apply trace ACTION to the function at point and describe the outcome.
@@ -651,19 +650,23 @@ the thrown error, or a named argument."
651650
(user-error "No call at point"))))
652651
(cider-tree-view-node-value node)))
653652

654-
(defconst sayid-tree--empty-workspace-hint
655-
"The workspace is empty - Sayid hasn't recorded any calls yet.
653+
(defun sayid-tree--empty-workspace-hint ()
654+
"Build the hint shown in the workspace tree when nothing was recorded.
655+
The key sequences are looked up live, so a custom prefix shows correctly."
656+
(format "The workspace is empty - Sayid hasn't recorded any calls yet.
656657
657658
To record something:
658659
659-
1. Trace what you're interested in: `sayid-trace-fn' (`C-c s t t')
660+
1. Trace what you're interested in: `sayid-trace-fn' (`%s')
660661
traces the function at point, `sayid-trace-ns-in-file'
661-
(`C-c s t b') the current buffer's whole namespace.
662+
(`%s') the current buffer's whole namespace.
662663
2. Run some code that calls what you traced (eval a form,
663664
run a test, hit an endpoint).
664-
3. Refresh this buffer with `g' (or `C-c s w' from anywhere).
665+
3. Refresh this buffer with `g' (or `%s' from anywhere).
665666
"
666-
"What to show in the workspace tree buffer when nothing was recorded.")
667+
(sayid--key-hint #'sayid-trace-fn)
668+
(sayid--key-hint #'sayid-trace-ns-in-file)
669+
(sayid--key-hint #'sayid-tree-view-workspace)))
667670

668671
(defvar-local sayid-tree--refresh-fn nil
669672
"Function of no arguments that re-runs the fetch that produced this tree.")
@@ -686,6 +689,30 @@ so `sayid-tree-refresh' can re-run the fetch that produced this tree."
686689
(interactive)
687690
(funcall (or sayid-tree--refresh-fn #'sayid-tree-view-workspace)))
688691

692+
(defun sayid-tree--stale-query-hint ()
693+
"Build the hint shown when a refreshed query no longer matches anything."
694+
(format "This query no longer matches anything - the recording changed.
695+
696+
Press `w' for the full workspace, or trace and run something new
697+
\(`%s' traces the function at point).
698+
"
699+
(sayid--key-hint #'sayid-trace-fn)))
700+
701+
(defun sayid-tree--show-query (fetch-fn title empty-error &optional refreshing)
702+
"Fetch roots with FETCH-FN and render them as a tree titled TITLE.
703+
When nothing matches, signal EMPTY-ERROR - unless REFRESHING is non-nil
704+
\(a `sayid-tree-refresh' re-run of an existing view), where an emptied
705+
query renders as an empty tree with a hint, rather than erroring while
706+
the stale content stays on screen."
707+
(let ((roots (funcall fetch-fn))
708+
(refresh (lambda ()
709+
(sayid-tree--show-query fetch-fn title empty-error t))))
710+
(cond
711+
(roots (sayid-tree--render roots title nil refresh))
712+
(refreshing
713+
(sayid-tree--render nil title (sayid-tree--stale-query-hint) refresh))
714+
(t (user-error "%s" empty-error)))))
715+
689716
(defun sayid-tree--query-title (kind selector mod)
690717
"Build a tree title for a query of KIND on SELECTOR with modifier MOD."
691718
(format "Query: %s %s%s" kind selector
@@ -737,7 +764,11 @@ prompt for which value."
737764
(sayid-req-insert-content (list "op" "sayid-pprint-value"
738765
"trace-id" (nrepl-dict-get call "id")
739766
"path" path))
740-
(goto-char 1)
767+
;; Point may have landed back in the tree buffer; reset the pprint
768+
;; buffer's position without disturbing the tree's.
769+
(when-let* ((buf (get-buffer (car sayid-pprint-buf-spec))))
770+
(with-current-buffer buf
771+
(goto-char (point-min))))
741772
(sayid-select-default-buf)))
742773

743774
(defun sayid-tree-gen-instance-expr ()
@@ -756,14 +787,12 @@ it into the REPL replays the call."
756787

757788
(defun sayid-tree--show-fn-query (fn-name mod)
758789
"Fetch and render every recorded call of FN-NAME, with query modifier MOD."
759-
(let ((roots (sayid-req-get-value (list "op" "sayid-query-by-fn-data"
760-
"fn-name" fn-name
761-
"mod" mod))))
762-
(if roots
763-
(sayid-tree--render roots (sayid-tree--query-title "fn" fn-name mod)
764-
nil
765-
(lambda () (sayid-tree--show-fn-query fn-name mod)))
766-
(user-error "No recorded calls of %s" fn-name))))
790+
(sayid-tree--show-query
791+
(lambda () (sayid-req-get-value (list "op" "sayid-query-by-fn-data"
792+
"fn-name" fn-name
793+
"mod" mod)))
794+
(sayid-tree--query-title "fn" fn-name mod)
795+
(format "No recorded calls of %s" fn-name)))
767796

768797
(defun sayid-tree-query-fn (&optional arg)
769798
"Re-render the tree with every recorded call of the function at point.
@@ -774,14 +803,12 @@ With a prefix ARG, also prompt for a query modifier."
774803

775804
(defun sayid-tree--show-id-query (id mod)
776805
"Fetch and render the recorded call ID and its subtree, with modifier MOD."
777-
(let ((roots (sayid-req-get-value (list "op" "sayid-query-by-id-data"
778-
"trace-id" id
779-
"mod" mod))))
780-
(if roots
781-
(sayid-tree--render roots (sayid-tree--query-title "id" id mod)
782-
nil
783-
(lambda () (sayid-tree--show-id-query id mod)))
784-
(user-error "Call %s not found" id))))
806+
(sayid-tree--show-query
807+
(lambda () (sayid-req-get-value (list "op" "sayid-query-by-id-data"
808+
"trace-id" id
809+
"mod" mod)))
810+
(sayid-tree--query-title "id" id mod)
811+
(format "Call %s not found" id)))
785812

786813
(defun sayid-tree-query-id (&optional arg)
787814
"Re-render the tree focused on the call at point.
@@ -799,7 +826,8 @@ When nothing has been recorded yet the buffer explains how to get going.
799826
See `sayid-tree-mode' for the keys available in the tree buffer."
800827
(interactive)
801828
(let ((roots (sayid-req-get-value (list "op" "sayid-get-workspace-data"))))
802-
(sayid-tree--render roots "Sayid workspace" sayid-tree--empty-workspace-hint
829+
(sayid-tree--render roots "Sayid workspace"
830+
(sayid-tree--empty-workspace-hint)
803831
#'sayid-tree-view-workspace)))
804832

805833
(defvar sayid-tree-mode-map
@@ -908,15 +936,19 @@ management: \\<sayid-traced-tree-mode-map>\\[sayid-traced-enable] enable,
908936
\\[sayid-traced-inner-trace] inner-trace, \\[sayid-traced-outer-trace]
909937
outer-trace the entry at point, \\[sayid-traced-refresh] refresh the view.")
910938

911-
(defconst sayid-traced--empty-hint
912-
"Nothing is traced yet.
939+
(defun sayid-traced--empty-hint ()
940+
"Build the hint shown in the traced-functions buffer when nothing is traced.
941+
The key sequences are looked up live, so a custom prefix shows correctly."
942+
(format "Nothing is traced yet.
913943
914-
In a Clojure buffer, `sayid-trace-ns-in-file' (`C-c s t b') traces the
915-
buffer's namespace; `sayid-trace-ns-by-pattern' (`C-c s t p') traces
944+
In a Clojure buffer, `sayid-trace-ns-in-file' (`%s') traces the
945+
buffer's namespace; `sayid-trace-ns-by-pattern' (`%s') traces
916946
namespaces by a wildcard pattern. Then run some code and view the
917-
recording with `sayid-tree-view-workspace' (`C-c s w').
947+
recording with `sayid-tree-view-workspace' (`%s').
918948
"
919-
"What to show in the traced-functions buffer when nothing is traced.")
949+
(sayid--key-hint #'sayid-trace-ns-in-file)
950+
(sayid--key-hint #'sayid-trace-ns-by-pattern)
951+
(sayid--key-hint #'sayid-tree-view-workspace)))
920952

921953
(defvar-local sayid-traced--ns nil
922954
"The namespace filter this traced-functions buffer was rendered with.")
@@ -933,7 +965,7 @@ GROUPS is empty, show a hint on how to trace something instead."
933965
"Traced functions"
934966
(unless groups
935967
(lambda ()
936-
(insert (propertize sayid-traced--empty-hint
968+
(insert (propertize (sayid-traced--empty-hint)
937969
'face 'shadow)))))))
938970

939971
(defun sayid-traced-refresh ()

‎test/el/sayid-test.el‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,37 @@
281281
(expect (spy-calls-count 'sayid-req-get-value) :to-equal 2)
282282
(expect (car (spy-calls-args-for 'sayid-req-get-value 1))
283283
:to-equal '("op" "sayid-query-by-fn-data" "fn-name" "my.ns/foo" "mod" ""))
284-
(kill-buffer "*sayid-tree*")))
284+
(kill-buffer "*sayid-tree*"))
285+
286+
(it "renders an emptied query as an empty view instead of erroring"
287+
(spy-on 'cider-popup-buffer :and-call-fake
288+
(lambda (name _select mode _ancillary)
289+
(with-current-buffer (get-buffer-create name)
290+
(funcall mode)
291+
(current-buffer))))
292+
(let ((first-call t))
293+
(spy-on 'sayid-req-get-value :and-call-fake
294+
(lambda (_req)
295+
(prog1 (when first-call
296+
(list (nrepl-dict "id" "1" "name" "my.ns/foo"
297+
"return" "1")))
298+
(setq first-call nil)))))
299+
(sayid-tree--show-fn-query "my.ns/foo" "")
300+
(with-current-buffer "*sayid-tree*"
301+
(sayid-tree-refresh)
302+
(expect (buffer-string) :to-match "no longer matches"))
303+
(kill-buffer "*sayid-tree*"))
304+
305+
(it "keeps the namespace filter when refreshing the visible traced view"
306+
(let ((buf (get-buffer-create "*traced-test*")))
307+
(with-current-buffer buf
308+
(setq-local sayid-traced--ns "my.ns"))
309+
(spy-on 'get-buffer-window :and-return-value (selected-window))
310+
(spy-on 'window-buffer :and-return-value buf)
311+
(spy-on 'sayid-show-traced)
312+
(sayid--refresh-traced-if-visible)
313+
(expect 'sayid-show-traced :to-have-been-called-with "my.ns")
314+
(kill-buffer buf))))
285315

286316
(describe "sayid-tree-inspect"
287317
(before-each

0 commit comments

Comments
 (0)