@@ -7,7 +7,7 @@ using Markdown
7
7
using Base. Docs: catdoc, modules, DocStr, Binding, MultiDoc, keywords, isfield, namify, bindingexpr,
8
8
defined, resolve, getdoc, meta, aliasof, signature
9
9
10
- import Base. Docs: doc, formatdoc, parsedoc, apropos
10
+ import Base. Docs: formatdoc, parsedoc, apropos
11
11
12
12
using Base: with_output_color, mapany, isdeprecated, isexported
13
13
@@ -206,55 +206,31 @@ function insert_internal_warning(other, internal_access::Set{Pair{Module,Symbol}
206
206
other
207
207
end
208
208
209
- function doc (binding:: Binding , sig:: Type = Union{})
209
+ function doc_as_md (binding:: Binding , sig:: Type = Union{})
210
210
if defined (binding)
211
211
result = getdoc (resolve (binding), sig)
212
212
result === nothing || return result
213
213
end
214
- results, groups = DocStr[], MultiDoc[]
215
- # Lookup `binding` and `sig` for matches in all modules of the docsystem.
216
- for mod in modules
217
- dict = meta (mod; autoinit= false )
218
- isnothing (dict) && continue
219
- if haskey (dict, binding)
220
- multidoc = dict[binding]
221
- push! (groups, multidoc)
222
- for msig in multidoc. order
223
- sig <: msig && push! (results, multidoc. docs[msig])
224
- end
225
- end
226
- end
227
- if isempty (groups)
228
- # When no `MultiDoc`s are found that match `binding` then we check whether `binding`
229
- # is an alias of some other `Binding`. When it is we then re-run `doc` with that
230
- # `Binding`, otherwise if it's not an alias then we generate a summary for the
231
- # `binding` and display that to the user instead.
232
- alias = aliasof (binding)
233
- alias == binding ? summarize (alias, sig) : doc (alias, sig)
214
+ result = Base. Docs. doc (binding, sig)
215
+ if result === nothing
216
+ return summarize (binding, sig)
234
217
else
235
- # There was at least one match for `binding` while searching. If there weren't any
236
- # matches for `sig` then we concatenate *all* the docs from the matching `Binding`s.
237
- if isempty (results)
238
- for group in groups, each in group. order
239
- push! (results, group. docs[each])
240
- end
218
+ if ! (result isa Vector)
219
+ result = [result]
241
220
end
242
- # Get parsed docs and concatenate them.
243
- md = catdoc (mapany (parsedoc, results)... )
221
+ md = catdoc (mapany (parsedoc, result)... )
244
222
# Save metadata in the generated markdown.
245
223
if isa (md, Markdown. MD)
246
- md. meta[:results ] = results
224
+ md. meta[:results ] = result
247
225
md. meta[:binding ] = binding
248
226
md. meta[:typesig ] = sig
249
227
end
250
228
return md
251
229
end
252
230
end
253
231
254
- # Some additional convenience `doc` methods that take objects rather than `Binding`s.
255
- doc (obj:: UnionAll ) = doc (Base. unwrap_unionall (obj))
256
- doc (object, sig:: Type = Union{}) = doc (aliasof (object, typeof (object)), sig)
257
- doc (object, sig... ) = doc (object, Tuple{sig... })
232
+ doc_as_md (obj:: UnionAll ) = doc_as_md (Base. unwrap_unionall (obj))
233
+ doc_as_md (object, sig:: Type = Union{}) = doc_as_md (aliasof (object, typeof (object)), sig)
258
234
259
235
function lookup_doc (ex)
260
236
if isa (ex, Expr) && ex. head != = :(.) && Base. isoperator (ex. head)
@@ -266,7 +242,7 @@ function lookup_doc(ex)
266
242
elseif Meta. isexpr (ex, :incomplete )
267
243
return :($ (Markdown. md " No documentation found." ))
268
244
elseif ! isa (ex, Expr) && ! isa (ex, Symbol)
269
- return :($ (doc )($ (typeof)($ (esc (ex)))))
245
+ return :($ (doc_as_md )($ (typeof)($ (esc (ex)))))
270
246
end
271
247
if isa (ex, Symbol) && Base. isoperator (ex)
272
248
str = string (ex)
@@ -287,12 +263,16 @@ function lookup_doc(ex)
287
263
binding = esc (bindingexpr (namify (ex)))
288
264
if isexpr (ex, :call ) || isexpr (ex, :macrocall ) || isexpr (ex, :where )
289
265
sig = esc (signature (ex))
290
- :($ (doc )($ binding, $ sig))
266
+ :($ (doc_as_md )($ binding, $ sig))
291
267
else
292
- :($ (doc )($ binding))
268
+ :($ (doc_as_md )($ binding))
293
269
end
294
270
end
295
271
272
+ macro showdoc (ex)
273
+ lookup_doc (ex)
274
+ end
275
+
296
276
# Object Summaries.
297
277
# =================
298
278
@@ -570,7 +550,7 @@ isregex(x) = isexpr(x, :macrocall, 3) && x.args[1] === Symbol("@r_str") && !isem
570
550
571
551
repl (io:: IO , ex:: Expr ; brief:: Bool = true , mod:: Module = Main, internal_accesses:: Union{Nothing, Set{Pair{Module,Symbol}}} = nothing ) = isregex (ex) ? :(apropos ($ io, $ ex)) : _repl (ex, brief, mod, internal_accesses)
572
552
repl (io:: IO , str:: AbstractString ; brief:: Bool = true , mod:: Module = Main, internal_accesses:: Union{Nothing, Set{Pair{Module,Symbol}}} = nothing ) = :(apropos ($ io, $ str))
573
- repl (io:: IO , other; brief:: Bool = true , mod:: Module = Main, internal_accesses:: Union{Nothing, Set{Pair{Module,Symbol}}} = nothing ) = esc (:(@doc $ other)) # TODO : track internal_accesses
553
+ repl (io:: IO , other; brief:: Bool = true , mod:: Module = Main, internal_accesses:: Union{Nothing, Set{Pair{Module,Symbol}}} = nothing ) = esc (:(REPL . @showdoc $ other)) # TODO : track internal_accesses
574
554
# repl(io::IO, other) = lookup_doc(other) # TODO
575
555
576
556
repl (x; brief:: Bool = true , mod:: Module = Main) = repl (stdout , x; brief, mod)
@@ -629,7 +609,7 @@ function _repl(x, brief::Bool=true, mod::Module=Main, internal_accesses::Union{N
629
609
end
630
610
end
631
611
# docs = lookup_doc(x) # TODO
632
- docs = esc (:(@doc $ x))
612
+ docs = esc (:($ REPL . @showdoc $ x))
633
613
docs = if isfield (x)
634
614
quote
635
615
if isa ($ (esc (x. args[1 ])), DataType)
@@ -983,7 +963,7 @@ apropos(io::IO, string) = apropos(io, Regex("\\Q$string", "i"))
983
963
function apropos (io:: IO , needle:: Regex )
984
964
for mod in modules
985
965
# Module doc might be in README.md instead of the META dict
986
- docsearch (doc (mod), needle) && println (io, mod)
966
+ docsearch (doc_as_md (mod), needle) && println (io, mod)
987
967
dict = meta (mod; autoinit= false )
988
968
isnothing (dict) && continue
989
969
for (k, v) in dict
0 commit comments