mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Add doc-of
function to core for reverse documentation lookup.
This commit is contained in:
parent
9078d3bd37
commit
dfbdd17dce
@ -2,6 +2,7 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased - ???
|
## Unreleased - ???
|
||||||
|
- Add `doc-of` for reverse documentation lookup.
|
||||||
- Add `ev/gather` and `chan` argument to `ev/go`. This new argument allows "supervisor channels"
|
- Add `ev/gather` and `chan` argument to `ev/go`. This new argument allows "supervisor channels"
|
||||||
for fibers to enable structured concurrency.
|
for fibers to enable structured concurrency.
|
||||||
- Make `-k` flag work on stdin if no files are given.
|
- Make `-k` flag work on stdin if no files are given.
|
||||||
|
@ -2018,20 +2018,8 @@
|
|||||||
(print (doc-format (string "Dynamics:\n\n" (string/join dynamics " "))))
|
(print (doc-format (string "Dynamics:\n\n" (string/join dynamics " "))))
|
||||||
(print "\n Use (doc sym) for more information on a binding.\n"))
|
(print "\n Use (doc sym) for more information on a binding.\n"))
|
||||||
|
|
||||||
(defn doc*
|
(defn- print-module-entry
|
||||||
"Get the documentation for a symbol in a given environment. Function form of doc."
|
[x]
|
||||||
[&opt sym]
|
|
||||||
|
|
||||||
(cond
|
|
||||||
(string? sym)
|
|
||||||
(print-index (fn [x] (string/find sym x)))
|
|
||||||
|
|
||||||
sym
|
|
||||||
(do
|
|
||||||
(def x (dyn sym))
|
|
||||||
(if (not x)
|
|
||||||
(print "symbol " sym " not found.")
|
|
||||||
(do
|
|
||||||
(def bind-type
|
(def bind-type
|
||||||
(string " "
|
(string " "
|
||||||
(cond
|
(cond
|
||||||
@ -2047,7 +2035,26 @@
|
|||||||
(string " " path " on line " line ", column " col "\n") "")
|
(string " " path " on line " line ", column " col "\n") "")
|
||||||
(if (or d sm) "\n" "")
|
(if (or d sm) "\n" "")
|
||||||
(if d (doc-format d) " no documentation found.")
|
(if d (doc-format d) " no documentation found.")
|
||||||
"\n\n"))))
|
"\n\n"))
|
||||||
|
|
||||||
|
(def module/cache
|
||||||
|
"Table mapping loaded module identifiers to their environments."
|
||||||
|
@{})
|
||||||
|
|
||||||
|
(defn doc*
|
||||||
|
"Get the documentation for a symbol in a given environment. Function form of doc."
|
||||||
|
[&opt sym]
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(string? sym)
|
||||||
|
(print-index (fn [x] (string/find sym x)))
|
||||||
|
|
||||||
|
sym
|
||||||
|
(do
|
||||||
|
(def x (dyn sym))
|
||||||
|
(if (not x)
|
||||||
|
(print "symbol " sym " not found.")
|
||||||
|
(print-module-entry x)))
|
||||||
|
|
||||||
# else
|
# else
|
||||||
(print-index identity)))
|
(print-index identity)))
|
||||||
@ -2060,8 +2067,25 @@
|
|||||||
[&opt sym]
|
[&opt sym]
|
||||||
~(,doc* ',sym))
|
~(,doc* ',sym))
|
||||||
|
|
||||||
|
(defn doc-of
|
||||||
|
`Searches all loaded modules in module/cache for a given binding and prints out its documentation.
|
||||||
|
This does a search by value instead of by name. Returns nil.`
|
||||||
|
[x]
|
||||||
|
(var found false)
|
||||||
|
(loop [module-set :in [[root-env] module/cache]
|
||||||
|
module :in module-set
|
||||||
|
value :in module]
|
||||||
|
(let [check (or (get value :ref) (get value :value))]
|
||||||
|
(when (= check x)
|
||||||
|
(print-module-entry value)
|
||||||
|
(set found true)
|
||||||
|
(break))))
|
||||||
|
(if-not found
|
||||||
|
(print "documentation for value " x " not found.")))
|
||||||
|
|
||||||
(undef env-walk)
|
(undef env-walk)
|
||||||
(undef print-index)
|
(undef print-index)
|
||||||
|
(undef print-module-entry)
|
||||||
|
|
||||||
###
|
###
|
||||||
###
|
###
|
||||||
@ -2644,10 +2668,6 @@
|
|||||||
(setdyn :syspath (boot/opts "JANET_PATH"))
|
(setdyn :syspath (boot/opts "JANET_PATH"))
|
||||||
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
|
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
|
||||||
|
|
||||||
(def module/cache
|
|
||||||
"Table mapping loaded module identifiers to their environments."
|
|
||||||
@{})
|
|
||||||
|
|
||||||
(defn module/add-paths
|
(defn module/add-paths
|
||||||
```
|
```
|
||||||
Add paths to module/paths for a given loader such that
|
Add paths to module/paths for a given loader such that
|
||||||
|
Loading…
Reference in New Issue
Block a user