Skip to content

Commit f60ea6c

Browse files
committed
middleware.info: offer new var-meta-allowlist option
Fixes #851
1 parent 09d4a34 commit f60ea6c

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
### Changes
66

7+
* Bump `orchard` to [0.23.0](https://github.com/clojure-emacs/orchard/blob/v0.23.0/CHANGELOG.md#0230-2024-03-03).
78
* Bump `logjam` to [0.3.0](https://github.com/clojure-emacs/logjam/blob/v0.3.0/CHANGELOG.md#030-2024-03-03).
9+
* [#851](https://github.com/clojure-emacs/cider-nrepl/issues/851): `middleware.info`: offer new `var-meta-allowlist` option.
810

911
## Bugs fixed
1012

doc/modules/ROOT/pages/nrepl-api/ops.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ making the results more accurate (and less numerous).
317317
* `:member` A Java class member.
318318
* `:ns` The current namespace
319319
* `:sym` The symbol to lookup
320+
* `:var-meta-allowlist` The metadata keys from vars to be returned. Currently only affects ``:clj``.
321+
Defaults to the value of ``orchard.meta/var-meta-allowlist``.
322+
If specified, the value will be concatenated to that of ``orchard.meta/var-meta-allowlist``.
320323

321324

322325
Returns::
@@ -451,6 +454,9 @@ making the results more accurate (and less numerous).
451454
* `:member` A Java class member.
452455
* `:ns` The current namespace
453456
* `:sym` The symbol to lookup
457+
* `:var-meta-allowlist` The metadata keys from vars to be returned. Currently only affects ``:clj``.
458+
Defaults to the value of ``orchard.meta/var-meta-allowlist``.
459+
If specified, the value will be concatenated to that of ``orchard.meta/var-meta-allowlist``.
454460

455461

456462
Returns::

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:url "http://www.eclipse.org/legal/epl-v10.html"}
99
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
1010
:dependencies [[nrepl "1.0.0"]
11-
[cider/orchard "0.22.0"]
11+
[cider/orchard "0.23.0"]
1212
^:inline-dep [mx.cider/haystack "0.3.3" :exclusions [cider/orchard]]
1313
^:inline-dep [thunknyc/profile "0.5.2"]
1414
^:inline-dep [mvxcvi/puget "1.3.4"]

src/cider/nrepl.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,17 @@ Depending on the type of the return value of the evaluation this middleware may
272272
"doc-block-tags-fragments" (str "May be absent. Represent the 'param', 'returns' and 'throws' sections a Java doc comment. " fragments-desc)})
273273

274274
(def info-params
275-
{"sym" "The symbol to lookup"
276-
"ns" "The current namespace"
277-
"context" "A Compliment completion context, just like the ones already passed for the \"complete\" op,
275+
{"sym" "The symbol to lookup"
276+
"ns" "The current namespace"
277+
"context" "A Compliment completion context, just like the ones already passed for the \"complete\" op,
278278
with the difference that the symbol at point should be entirely replaced by \"__prefix__\".
279279
For Java interop queries, it helps inferring the precise type of the object the `:sym` or `:member` refers to,
280280
making the results more accurate (and less numerous)."
281-
"class" "A Java class. If `:ns` is passed, it will be used for fully-qualifiying the class, if necessary."
282-
"member" "A Java class member."})
281+
"class" "A Java class. If `:ns` is passed, it will be used for fully-qualifiying the class, if necessary."
282+
"member" "A Java class member."
283+
"var-meta-allowlist" "The metadata keys from vars to be returned. Currently only affects `:clj`.
284+
Defaults to the value of `orchard.meta/var-meta-allowlist`.
285+
If specified, the value will be concatenated to that of `orchard.meta/var-meta-allowlist`."})
283286

284287
(def-wrapper wrap-info cider.nrepl.middleware.info/handle-info
285288
(cljs/requires-piggieback

src/cider/nrepl/middleware/info.clj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[clojure.string :as str]
99
[orchard.eldoc :as eldoc]
1010
[orchard.info :as info]
11+
[orchard.meta :as meta]
1112
[orchard.misc :as misc]))
1213

1314
(declare format-response)
@@ -74,8 +75,11 @@
7475
;; We can always be analyzing a broken context.
7576
nil))))
7677

78+
(def var-meta-allowlist-set
79+
(set meta/var-meta-allowlist))
80+
7781
(defn info
78-
[{:keys [ns sym class member context]
82+
[{:keys [ns sym class member context var-meta-allowlist]
7983
legacy-sym :symbol
8084
:as msg}]
8185
(let [sym (or (not-empty legacy-sym)
@@ -108,7 +112,11 @@
108112
:sym sym}
109113
(when env
110114
{:env env
111-
:dialect :cljs}))]
115+
:dialect :cljs})
116+
(when var-meta-allowlist
117+
{:var-meta-allowlist (into meta/var-meta-allowlist
118+
(remove var-meta-allowlist-set)
119+
var-meta-allowlist)}))]
112120
(cond
113121
java? (info/info-java class (or member sym))
114122
(and ns sym) (info/info* info-params)

test/clj/cider/nrepl/middleware/info_test.clj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
info/format-response
8383
(dissoc "file" "see-also"))))))
8484

85+
(defn var-with-custom-meta
86+
{:custom/meta 1}
87+
[foo]
88+
:bar)
89+
8590
(deftest info-test
8691
;; handle zero-length input
8792
(is (nil? (info/info {:ns (str (ns-name *ns*)) :sym ""})))
@@ -97,6 +102,16 @@
97102
(is (contains? (info/info {:ns (-> ::_ namespace str)
98103
:sym "ns-resolve"})
99104
:doc))
105+
106+
(testing "`:var-meta-allowlist`"
107+
(let [base-keys [:ns :name :file :arglists :line :column]]
108+
(is (= base-keys (keys (info/info {:ns (-> ::_ namespace str)
109+
:sym "var-with-custom-meta"}))))
110+
(is (= (conj base-keys :custom/meta)
111+
(keys (info/info {:ns (-> ::_ namespace str)
112+
:sym "var-with-custom-meta"
113+
:var-meta-allowlist [:custom/meta]}))))))
114+
100115
(is (= (info/info {:ns (-> ::_ namespace str)
101116
:sym "ns-resolve"})
102117
(info/info {:ns (-> ::_ namespace str)

0 commit comments

Comments
 (0)