Skip to content

Commit 38c48b3

Browse files
committed
add method list to datatip (collapsed by default)
1 parent 345dc51 commit 38c48b3

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/datatip.jl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#=
2-
@TODO:
3-
Use our own UI components for this: atom-ide-ui is already deprecated, ugly, not fully functional, and and...
4-
Once we can come to handle links within datatips, we may want to append method tables as well
2+
@TODO use our own UI components for this:
3+
atom-ide-ui is already deprecated, ugly, not fully functional, and and...
54
=#
65

76
handle("datatip") do data
@@ -74,6 +73,9 @@ function globaldatatip(mod, word, fullword)
7473

7574
processdoc!(docs, docstr, datatip)
7675

76+
ml = methods(val)
77+
processmethods!(ml, datatip)
78+
7779
return datatip
7880
end
7981

@@ -125,6 +127,23 @@ processval!(val::Function, docstr, datatip) = begin
125127
end
126128
processval!(::Undefined, docstr, datatip) = nothing
127129

130+
function processmethods!(ml, datatip)
131+
ms = collect(ml)
132+
isempty(ms) && return
133+
134+
replace(str, mregex => s"\g<sig> aviin \g<mod> aviat \g<loc>")
135+
136+
substr = s"<code>\g<sig></code> in <code>\g<mod></code> at \g<loc>"
137+
msstr = map(ms) do m
138+
s = replace(string(m), methodloc_regex => substr)
139+
match(methodloc_regex, string(m))
140+
"<li>$s</li>"
141+
end |> join
142+
143+
name = ms[1].name
144+
pushmarkdown!(datatip, "<details><summary><code>$name</code> has **$(length(ms))** methods:</summary><ul>$(msstr)</ul></details>")
145+
end
146+
128147
function pushmarkdown!(datatip, markdown)
129148
(markdown == "" || markdown == "\n") && return
130149
push!(datatip, Dict(:type => :markdown, :value => markdown))

src/display/methods.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ stripparams(t) = replace(t, r"\{([A-Za-z, ]*?)\}" => "")
44

55
interpose(xs, y) = map(i -> iseven(i) ? xs[i÷2] : y, 2:2length(xs))
66

7+
const methodloc_regex = r"(?<sig>.+) in (?<mod>.+) at (?<loc>.+)$"
8+
79
function view(m::Method)
810
str = sprint(show, "text/html", m)
9-
str = replace(str, r" in .* at .*$" => "")
11+
str = replace(str, methodloc_regex => s"\g<sig>")
1012
str = string("<span>", str, "</span>")
1113
tv, decls, file, line = Base.arg_decl_parts(m)
1214
HTML(str), file == :null ? "not found" : Atom.baselink(string(file), line)

0 commit comments

Comments
 (0)