Skip to content

Instantly share code, notes, and snippets.

@ZacLN
Created December 15, 2016 00:19
Show Gist options
  • Save ZacLN/e99fde05fceda1c86bfb817cde25c0ee to your computer and use it in GitHub Desktop.
Save ZacLN/e99fde05fceda1c86bfb817cde25c0ee to your computer and use it in GitHub Desktop.
import LanguageServer: get_docs, Location
import Base.REPLCompletions: get_value
function modnames(m::AbstractString, top)
s = Symbol(m)
eval(:(using $s))
M, exists = get_value(s, Main)
if !(s in keys(top))
modnames(M, top)
end
pdir = Pkg.dir(m)
if isdir(pdir)
flist = readdir(pdir)
if isfile(pdir*"/REQUIRE")
incls = filter!(i->i!="julia",(f->match(r"^\S*",f).match).(chomp.(readlines(pdir*"/REQUIRE"))))
for i in incls
x, exists = get_value(Symbol(i), Main)
modnames(x, top)
top[s][Symbol(i)] = top[Symbol(i)]
end
end
end
end
function modnames(M::Module, top)
s = parse(string(M))
s in keys(top) && return
d = Dict{Any,Any}()
top[s] = d
for n in names(M, true, true)
x, exists = get_value(n, M)
if exists
if isa(x, Module)
if x==M
continue
elseif n in keys(top)
# d[n] = top[n]
else
# top[n] = modnames(x, top)
modnames(x, top)
# d[n] = top[n]
end
elseif first(string(n))!='#'
t = isa(x, Function) ? Function :
isa(x, DataType) ? DataType :
typeof(x)
try
temp = map(Base.arg_decl_parts, methods(x))
rt = isempty(temp) ? [] : Base.return_types(x)
desc = map(temp,rt) do d,r
args = [Expr(:(::), parse(d[2][i][1]), parse(d[2][i][2])) for i = 2:length(d[2])]
loc = Location(string(d[3]),d[4]-1)
# return (args, t, loc)
return (args, string(d[3]), d[4]-1)
end
docs = get_docs(x)
if typeof(docs).parameters[1]==LanguageServer.MarkedString
docs = (d->string(d.value)).(docs)
end
d[n] = (t, desc, docs)
end
end
end
end
return d
end
top = Dict()
@time modnames(LanguageServer, top)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment