1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-04 15:56:17 +00:00

Make doc work for special forms

This commit is contained in:
sogaiu 2021-05-06 21:21:23 +09:00
parent c3f770da27
commit e5a2df93ab

View File

@ -2891,6 +2891,13 @@
(if d (doc-format d) " no documentation found.") (if d (doc-format d) " no documentation found.")
"\n\n")) "\n\n"))
(defn- print-special-form-entry
[x]
(print "\n\n"
(string " special form\n\n")
(string " (" x " ...)\n\n")
(string " See https://janet-lang.org/docs/specials.html\n\n")))
(defn doc* (defn doc*
"Get the documentation for a symbol in a given environment. Function form of doc." "Get the documentation for a symbol in a given environment. Function form of doc."
[&opt sym] [&opt sym]
@ -2903,14 +2910,17 @@
(do (do
(def x (dyn sym)) (def x (dyn sym))
(if (not x) (if (not x)
(do (if (index-of sym '[break def do fn if quasiquote quote
(def [fullpath mod-kind] (module/find (string sym))) set splice unquote upscope var while])
(if-let [mod-env (in module/cache fullpath)] (print-special-form-entry sym)
(print-module-entry {:module true (do
:kind mod-kind (def [fullpath mod-kind] (module/find (string sym)))
:source-map [fullpath nil nil] (if-let [mod-env (in module/cache fullpath)]
:doc (in mod-env :doc)}) (print-module-entry {:module true
(print "symbol " sym " not found."))) :kind mod-kind
:source-map [fullpath nil nil]
:doc (in mod-env :doc)})
(print "symbol " sym " not found."))))
(print-module-entry x))) (print-module-entry x)))
# else # else