Skip to content

Commit 186b497

Browse files
authored
[Fix #3200] Improve browse-ns interface with filters and groupings (#3217)
Major re-work of the browse-ns interface, as well as fixing misc bug. - cider-browse-ns--thing-at-point didn't distinguish a ns without '.' - Added helper nrepl-dict-filter to filter entries in a nrepl-dict - added grouping feature and corresponding keybindings - added filtering features and corresponding keybindings - added new local vars to aid in re-displaying buffer
1 parent 14246b8 commit 186b497

File tree

8 files changed

+416
-51
lines changed

8 files changed

+416
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## Changes
1010

1111
* Upgrade injected `cider-nrepl` to [0.28.5](https://github.com/clojure-emacs/cider-nrepl/releases/tag/v0.28.5).
12+
* [#3200](https://github.com/clojure-emacs/cider/issues/3200): Improve cider-browse-ns interface to allow selective hiding of var types as well as grouping options. Include private vars in result list.
1213

1314
## 1.4.1 (2022-05-25)
1415

cider-browse-ns.el

Lines changed: 354 additions & 37 deletions
Large diffs are not rendered by default.

cider-client.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,15 @@ returned."
743743
(cider-nrepl-send-sync-request)
744744
(nrepl-dict-get "ns-vars-with-meta")))
745745

746+
(defun cider-sync-request:private-ns-vars-with-meta (ns)
747+
"Get a map of the vars in NS to its metadata information."
748+
(thread-first `("op" "ns-vars-with-meta"
749+
"ns" ,ns
750+
"var-query" ,(nrepl-dict "private?" "t"
751+
"include-meta-key" '("private")))
752+
(cider-nrepl-send-sync-request)
753+
(nrepl-dict-get "ns-vars-with-meta")))
754+
746755
(defun cider-sync-request:ns-load-all ()
747756
"Load all project namespaces."
748757
(thread-first '("op" "ns-load-all")

cider-debug.el

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,24 @@ configure `cider-debug-prompt' instead."
103103

104104

105105
;;; Implementation
106+
(declare-function cider-browse-ns--combined-vars-with-meta "cider-browse-ns")
107+
106108
(defun cider-browse-instrumented-defs ()
107109
"List all instrumented definitions."
108110
(interactive)
109111
(if-let* ((all (thread-first (cider-nrepl-send-sync-request '("op" "debug-instrumented-defs"))
110112
(nrepl-dict-get "list"))))
111113
(with-current-buffer (cider-popup-buffer cider-browse-ns-buffer t)
112114
(let ((inhibit-read-only t))
113-
(erase-buffer)
114115
(dolist (list all)
115116
(let* ((ns (car list))
116-
(ns-vars-with-meta (cider-sync-request:ns-vars-with-meta ns))
117-
;; seq of metadata maps of the instrumented vars
118-
(instrumented-meta (mapcar (apply-partially #'nrepl-dict-get ns-vars-with-meta)
119-
(cdr list))))
117+
(ns-vars-with-meta (cider-browse-ns--combined-vars-with-meta ns))
118+
(instrumented-meta (nrepl-dict-filter (lambda (k _)
119+
(member k list))
120+
ns-vars-with-meta)))
120121
(cider-browse-ns--list (current-buffer) ns
121-
(seq-mapn #'cider-browse-ns--properties
122-
(cdr list)
123-
instrumented-meta)
124-
125-
ns 'noerase)
126-
(goto-char (point-max))
127-
(insert "\n"))))
128-
(goto-char (point-min)))
122+
instrumented-meta
123+
ns)))))
129124
(message "No currently instrumented definitions")))
130125

131126
(defun cider--debug-response-handler (response)
-73.3 KB
Loading

doc/modules/ROOT/pages/usage/misc_features.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ image::ns_browser.png[Namespace Browser]
224224
You can also browse all available namespaces with kbd:[M-x]
225225
`cider-browse-ns-all`.
226226

227+
The UI contains buttons in the header which allow you to control how
228+
the buffer is displayed (see below for keybindings). You may also
229+
configure the `cider-browse-ns-default-filters` variable to a list of
230+
the element types you want to be hidden by default.
231+
227232
There are a bunch of useful keybindings that are defined in browser buffers.
228233

229234
|===
@@ -244,6 +249,27 @@ There are a bunch of useful keybindings that are defined in browser buffers.
244249
| kbd:[n]
245250
| Go to next line.
246251

252+
| kbd:[h p]
253+
| Toggle visibility of private items.
254+
255+
| kbd:[h t]
256+
| Toggle visibility of tests.
257+
258+
| kbd:[h m]
259+
| Toggle visibility of macros.
260+
261+
| kbd:[h f]
262+
| Toggle visibility of functions.
263+
264+
| kbd:[h v]
265+
| Toggle visibility of vars.
266+
267+
| kbd:[g t]
268+
| Group items by type (function, macro, var, etc.).
269+
270+
| kbd:[g v]
271+
| Group items by visibility (public vs. private).
272+
247273
| kbd:[p]
248274
| Go to previous line.
249275
|===

nrepl-dict.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ also always return a sequence (since the result will be flattened)."
128128
(when dict
129129
(apply #'append (nrepl-dict-map function dict))))
130130

131+
(defun nrepl-dict-filter (function dict)
132+
"For all key-values of DICT, return new dict where FUNCTION returns non-nil.
133+
134+
FUNCTION should be a function taking two arguments, key and value."
135+
(let ((new-map (nrepl-dict))
136+
(keys (nrepl-dict-keys dict)))
137+
(dolist (key keys)
138+
(let ((val (nrepl-dict-get dict key)))
139+
(when (funcall function key val)
140+
(nrepl-dict-put new-map key val))))
141+
new-map))
142+
131143

132144
;;; More specific functions
133145
(defun nrepl--cons (car list-or-dict)

test/cider-browse-ns-tests.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'(dict "blank?"
5151
(dict "arglists" "fn arg list"
5252
"doc" "\"True if s is nil, empty, or contains only whitespace.\"")))
53+
(spy-on 'cider-sync-request:private-ns-vars-with-meta :and-return-value '(dict))
5354

5455
(with-temp-buffer
5556
(setq cider-browse-ns-buffer (buffer-name (current-buffer)))
@@ -59,7 +60,11 @@
5960
(search-forward "blank")
6061
(expect (get-text-property (point) 'font-lock-face) :to-equal 'font-lock-function-name-face)
6162
(search-forward "True")
62-
(expect (get-text-property (point) 'font-lock-face) :to-equal 'font-lock-doc-face))))
63+
(expect (get-text-property (point) 'font-lock-face) :to-equal 'font-lock-doc-face)
64+
;; filter out the functions and ensure that blank? doesn't show up
65+
(cider-browse-ns-toggle-hide-function)
66+
(goto-char (point-min))
67+
(expect (not (search-forward "blank" nil t))))))
6368

6469
(describe "cider-browse-ns--first-doc-line"
6570
(it "returns Not documented if the doc string is missing"

0 commit comments

Comments
 (0)