Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop methodtable in datatip #149

Merged
merged 2 commits into from
Aug 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 20 additions & 36 deletions src/datatip.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
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"
#=
@FIXME?
If we come to be able to use our full-featured components in atom-julia-client
for datatips, we may want to append method tables again.
Ref: https://github.com/JunoLab/atom-julia-client/blob/master/lib/runtime/datatip.js#L3-L9
=#

handle("datatip") do data
@destruct [mod || "Main", word] = data
Expand All @@ -12,20 +12,22 @@ handle("datatip") do data
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)
# @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`
# into an appropriate markdown string might be preferred.
"""
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)
# 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` into
# an appropriate markdown string might be preferred.
texts = split(string(docs), codeblock_regex)
codes = searchcodeblocks(docs)

Expand All @@ -35,7 +37,6 @@ function makedatatip(docs, word, mtable)
processmdcode!(code, datatips)
processmdtext!(text, datatips)
end
processmethodtable!(word, mtable, datatips)

datatips
end
Expand All @@ -44,6 +45,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 +72,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