Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

Live Docs: show package defining a function

Open fonsp opened this issue 2 years ago • 6 comments

When reading docs, it would be nice to show from which package a function/method originates.

Current:

image

fonsp avatar Dec 06 '23 12:12 fonsp

I did some experiments here, and the big question in this issue is on the Julia side:

Currently, we use Docs.doc(binding) to get documentation, but this just returns a Markdown.MD, but we are not sure how to get more info, such as:

  • For how many methods did you show docs? E.g. docs for sqrt gives two entries for two methods.
  • For each method:
    • In which package is it defined?
    • Can we get the Method object? (And link to the source code?)

fonsp avatar Oct 29 '24 09:10 fonsp

Why not evaluate the symbol (in a try/catch), and show its methods(f) if it is a function?

Incidentally, because I have JULIA_EDITOR configured, I can take advantage of

{4982748C-D3F4-41E7-B180-AF28308EF54D}

or type edit(some_function). It is super useful for debugging in the REPL, and there's no reason why Pluto couldn't link its stacktraces/methods in the same way. I can figure out the relevant methods if that helps.

cstjean avatar Oct 30 '24 01:10 cstjean

Yes amazing! For stacktraces we are have this already implemented: https://github.com/fonsp/Pluto.jl/pull/2813 and we are working on supporting URLs for more methods in https://github.com/JuliaPluto/MethodURL.jl (see https://github.com/JuliaLang/julia/issues/47709)

fonsp avatar Oct 31 '24 09:10 fonsp

Evaluating in trycatch and getting methods is a first step, the question is:

Docs.doc gives all docs for a search string as one single Markdown.MD object. And this object often contains docs for multiple methods.

What we want is to get something like:

[
	Dict(
		:method => "sqrt(::Matrix)",
		:method_url => "https://...",
		:docs => "<p>..."
	),
	Dict(
		:method => "sqrt(::Real)",
		...
	)
]

We can give this list to the frontend and show documentation for multiple methods in a nicer way, and include URLs to source code. I.e. the goal is to get more structured information than what Docs.doc currently provides, because that structured data allows the frontend to be more helpful.

fonsp avatar Oct 31 '24 09:10 fonsp

For stacktraces we are have this already implemented

Perhaps I'm missing something or I was not clear, but when I look at a StackTrace in Pluto,

{D81769B9-40DC-448E-917F-D408D56BF6FA}

There's nowhere I can click to go that that definition, right? Whereas in the REPL, I'd just type 5 and CTRL-q to immediately have my editor (eg. emacs) go to the line of that error.

I know this is already supported for code defined in the same Pluto notebook, but the REPL functionality works for any code.

That REPL code to do that is here: https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/src/REPL.jl#L1638. Being able to click somewhere in Pluto to open up my editor would be fantastic! Could be conditional on JULIA_EDITOR being defined, of course.

cstjean avatar Oct 31 '24 21:10 cstjean

You can click on the filename (ends in .jl), but it does not always work because of https://github.com/JuliaLang/julia/issues/47709 (when it does not work you cannot click).

fonsp avatar Nov 05 '24 09:11 fonsp