Skip to content

Commit be6d8e9

Browse files
committed
CLJS-3439: REPL doc support for externs
* break out ->pre * add cljs.analyzer.api/resolve-extern * new doc lookup path in repl for js/foo symbols
1 parent 5549175 commit be6d8e9

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,10 +977,13 @@
977977
(or (= 'js x)
978978
(= "js" (namespace x)))))
979979

980+
(defn ->pre [x]
981+
(->> (string/split (name x) #"\.") (map symbol)))
982+
980983
(defn normalize-js-tag [x]
981984
;; if not 'js, assume constructor
982985
(if-not (= 'js x)
983-
(let [props (->> (string/split (name x) #"\.") (map symbol))
986+
(let [props (->pre x)
984987
[xs y] ((juxt butlast last) props)]
985988
(with-meta 'js
986989
{:prefix (vec (concat xs [(with-meta y {:ctor true})]))}))

src/main/clojure/cljs/analyzer/api.cljc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@
218218
([state]
219219
(keys (get @state ::ana/namespaces))))
220220

221+
(defn resolve-extern
222+
"Given a symbol attempt to look it up in the provided externs"
223+
([sym]
224+
(resolve-extern env/*compiler* sym))
225+
([state sym]
226+
(let [pre (ana/->pre sym)]
227+
(env/with-compiler-env state
228+
(:info (ana/resolve-extern pre))))))
229+
221230
(defn find-ns
222231
"Given a namespace return the corresponding namespace analysis map. Analagous
223232
to clojure.core/find-ns."

src/main/clojure/cljs/repl.cljc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,11 @@ itself (not its value) is returned. The reader macro #'x expands to (var x)."}})
14471447
(keyword? name)
14481448
`(cljs.repl/print-doc {:spec ~name :doc (cljs.spec.alpha/describe ~name)})
14491449

1450+
(= "js" (namespace name))
1451+
`(cljs.repl/print-doc
1452+
(quote ~(merge (select-keys (ana-api/resolve-extern name) [:doc :arglists])
1453+
{:name name})))
1454+
14501455
(ana-api/find-ns name)
14511456
`(cljs.repl/print-doc
14521457
(quote ~(select-keys (ana-api/find-ns name) [:name :doc])))

0 commit comments

Comments
 (0)