Skip to content

Commit

Permalink
Drop method tables in datatip
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 3, 2019
1 parent 22449d5 commit 6db6e99
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions src/datatip.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
"""
Regex that matches for a Julia documentation text when there is no binding exists
for the target word.
Refered to https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/src/docview.jl#L152.
"""
const nobinding_regex = r"No documentation found.\n\nBinding `.*` does not exist.\n"

handle("datatip") do data
@destruct [mod || "Main", word] = data
docs = @errs getdocs(mod, word)

docs isa EvalError && return Dict(:error => true)
occursin(nobinding_regex, string(docs)) && return Dict(:novariable => true)

mtable = try getmethods(mod, word)
catch e
[]
end

Dict(:error => false,
:strings => makedatatip(docs, word, mtable))
:strings => makedatatip(docs))
end

function makedatatip(docs, word, mtable)
"""
Regex that matches for a Julia documentation text when there is no binding exists
for the target word.
Adapted from https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/src/docview.jl#L152.
"""
const nobinding_regex = r"No documentation found.\n\nBinding `.*` does not exist.\n"

function makedatatip(docs)
# @FIXME?: Separates code blocks from the other markdown texts in order to
# render them as code snippet text by atom-ide-ui's datatip service.
# Setting up functions to deconstruct each `Markdown.MD.content`
Expand All @@ -35,7 +30,6 @@ function makedatatip(docs, word, mtable)
processmdcode!(code, datatips)
processmdtext!(text, datatips)
end
processmethodtable!(word, mtable, datatips)

datatips
end
Expand All @@ -44,6 +38,7 @@ end
Regex to match code blocks from markdown texts.
"""
const codeblock_regex = r"```((?!```).)*?```"s

# Extract only code blocks from Markdown.MD
function searchcodeblocks(docs)
codeblocks = []
Expand All @@ -70,21 +65,3 @@ function processmdcode!(code, datatips)
push!(datatips, Dict(:type => :snippet,
:value => code))
end

function processmethodtable!(word, mtable, datatips)
isempty(mtable) && return

header = "\n***\n`$(word)` has **$(length(mtable))** methods\n"

body = map(mtable) do m
mstring = string(m)
text = mstring[1:match(r" at ", mstring).offset + 3]
isbase = m.module === Base || parentmodule(m.module) === Base
file = isbase ? basepath(string(m.file)) : m.file
# @NOTE: Datatip service component can't handle links to file paths.
"- $(text)$(file):$(m.line)"
end |> lists -> join(lists, "\n")

push!(datatips, Dict(:type => :markdown,
:value => header * body))
end

0 comments on commit 6db6e99

Please sign in to comment.