Skip to content

Commit 3ac6050

Browse files
committed
Add a resolving version of find-doc
That's what editors will typically when they want to fetch some ClojureDocs entry.
1 parent 2fe80a2 commit 3ac6050

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/orchard/clojuredocs.clj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,26 @@
8989
([ns sym export-edn-url]
9090
(get-doc (keyword ns sym) export-edn-url)))
9191

92+
(defn- var-name
93+
"Convert `v`'s name to a string we can use with `get-doc`."
94+
[v]
95+
(subs (str v) 2))
96+
97+
(defn resolve-and-find-doc
98+
"Resolve `sym` in the context of `ns` and look up the documentation
99+
for the resulting var."
100+
{:added "0.5.0"}
101+
[ns sym]
102+
(if (special-symbol? sym)
103+
(find-doc "clojure.core" (str sym))
104+
(-> (ns-resolve ns sym) var-name get-doc)))
105+
92106
(defn- kw-to-sym [kw]
93107
(symbol (subs (str kw) 1)))
94108

95109
(defn see-also
96110
"Get the see-alsos for `var-name` if any."
111+
{:added "0.5.0"}
97112
[var-name]
98113
(if-let [see-alsos (:see-alsos (get-doc var-name))]
99114
(map kw-to-sym see-alsos)))

0 commit comments

Comments
 (0)