File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 63
63
(m/special-sym-meta sym)
64
64
; ; it's a var
65
65
(some-> ns (m/resolve-var sym) (m/var-meta var-meta-allowlist))
66
+ ; ; it's a munged printed var or .invoke method of a Clojure function
67
+ (some-> (m/resolve-munged-printed-var sym) (m/var-meta var-meta-allowlist))
66
68
; ; it's a Java class/constructor/member symbol
67
69
(some-> ns (java/resolve-symbol sym))
68
70
; ; it's an alias for another ns
Original file line number Diff line number Diff line change 11
11
[orchard.namespace :as ns ]
12
12
[orchard.spec :as spec])
13
13
(:import
14
- (clojure.lang LineNumberingPushbackReader Namespace Var)))
14
+ (clojure.lang Compiler LineNumberingPushbackReader Namespace Var)))
15
15
16
16
; ;; ## Extractors
17
17
119
119
(when-let [ns (find-ns ns )]
120
120
(ns-aliases ns )))
121
121
122
+ (defn resolve-munged-printed-var
123
+ " Given a printed munged representation of Clojure function, try to resolve it as
124
+ a var. Supports the following representations:
125
+ - clojure.core$str
126
+ - clojure.core$str.invoke
127
+ - clojure.main$repl$fn__9119.invoke (resolves to named var, not internal lambda)
128
+ - some.ns$eval1234$closing_over_fn__12345.invoke"
129
+ [sym]
130
+ (let [demunged (-> (Compiler/demunge (str sym))
131
+ (string/replace #"--\d +" " " ))
132
+ [_ wo-method] (re-matches #"(.+?)(?:\. (?:invoke|invokeStatic|doInvoke))?"
133
+ demunged)
134
+ [ns-str name-str] (->> (string/split wo-method #"/" )
135
+ (remove #(re-matches #"eval\d +" %)))
136
+ ns (some-> ns-str symbol find-ns)
137
+ resolved (when (and ns name-str)
138
+ (ns-resolve ns (symbol name-str)))]
139
+ (when (var? resolved)
140
+ resolved)))
141
+
122
142
; ; Even if things like catch or finally aren't clojure special
123
143
; ; symbols we want to be able to talk about them.
124
144
; ; They just map to a special symbol.
Original file line number Diff line number Diff line change 191
191
(select-keys [:ns :name :arglists :doc ])
192
192
(update :ns ns-name))))))))
193
193
194
+ (let [a 1 ]
195
+ (defn- closed-over [] a ))
196
+
197
+ (deftest info-munged-printed-var-test
198
+ (is (= 'str
199
+ (:name (info/info 'orchard.test-ns 'clojure.core$str))))
200
+ (is (= 'str
201
+ (:name (info/info 'orchard.test-ns 'clojure.core$str.invoke))))
202
+ (is (= 'str
203
+ (:name (info/info 'orchard.test-ns 'clojure.core$str$fn__12.doInvoke))))
204
+ (is (= 'str
205
+ (:name (info/info 'orchard.test-ns (symbol " clojure.core/str/fn--12" )))))
206
+ (is (= 'closed-over
207
+ (:name (info/info 'orchard.test-ns 'orchard.info_test$eval17939$closed_over__17940.invokeStatic))))
208
+ (is (= 'closed-over
209
+ (:name (info/info 'orchard.test-ns (symbol " orchard.info-test/eval17939/closed_over--17940" ))))))
210
+
194
211
(deftest info-unqualified-sym-and-namespace-test
195
212
(testing " Resolution from current namespace"
196
213
(when cljs-available?
410
427
411
428
(when cljs-available?
412
429
(testing " - :cljs"
413
- (is (= (take 3 ( repeat expected) )
430
+ (is (= (repeat 3 expected)
414
431
(->> params
415
432
(map #(info/info* (merge @*cljs-params* %)))
416
433
(map #(select-keys % [:ns :name :arglists :macro :file ])))))))
417
434
418
435
(testing " - :clj"
419
- (is (= [{}, expected, {}]
436
+ (is (= ( repeat 3 expected)
420
437
(->> params
421
438
(map #(info/info* %))
422
439
(map #(select-keys % [:ns :name :arglists :macro :file ])))))))))
You can’t perform that action at this time.
0 commit comments