Skip to content

CLJS-3439: REPL doc support for externs #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -977,10 +977,13 @@
(or (= 'js x)
(= "js" (namespace x)))))

(defn ->pre [x]
(->> (string/split (name x) #"\.") (map symbol)))

(defn normalize-js-tag [x]
;; if not 'js, assume constructor
(if-not (= 'js x)
(let [props (->> (string/split (name x) #"\.") (map symbol))
(let [props (->pre x)
[xs y] ((juxt butlast last) props)]
(with-meta 'js
{:prefix (vec (concat xs [(with-meta y {:ctor true})]))}))
Expand Down
9 changes: 9 additions & 0 deletions src/main/clojure/cljs/analyzer/api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@
([state]
(keys (get @state ::ana/namespaces))))

(defn resolve-extern
"Given a symbol attempt to look it up in the provided externs"
([sym]
(resolve-extern env/*compiler* sym))
([state sym]
(let [pre (ana/->pre sym)]
(env/with-compiler-env state
(:info (ana/resolve-extern pre))))))

(defn find-ns
"Given a namespace return the corresponding namespace analysis map. Analagous
to clojure.core/find-ns."
Expand Down
5 changes: 5 additions & 0 deletions src/main/clojure/cljs/repl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,11 @@ itself (not its value) is returned. The reader macro #'x expands to (var x)."}})
(keyword? name)
`(cljs.repl/print-doc {:spec ~name :doc (cljs.spec.alpha/describe ~name)})

(= "js" (namespace name))
`(cljs.repl/print-doc
(quote ~(merge (select-keys (ana-api/resolve-extern name) [:doc :arglists])
{:name name})))

(ana-api/find-ns name)
`(cljs.repl/print-doc
(quote ~(select-keys (ana-api/find-ns name) [:name :doc])))
Expand Down