Created
December 2, 2016 08:11
-
-
Save ZacLN/111ffa8ee7cc28ac863de02835dba086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LanguageServer | |
import LanguageServer: Location, URIParser | |
import LanguageServer: get_docs, get_sym | |
const basenames = Symbol.(Base.REPLCompletions.completions("Base.",5)[1]) | |
function cachemodule(modulename::AbstractString) | |
mdir = Pkg.dir(modulename) | |
!Base.isdir(mdir) && error("Module `$modulename` is not installed") | |
jlfiles = filter!(f->ismatch(r".jl$", f), readdir(joinpath(mdir,"src"))) | |
@eval using $(Symbol(modulename)) | |
smodule = get_sym(modulename) | |
allnames = Symbol.(Base.REPLCompletions.completions(modulename*".",endof(modulename)+1)[1]) | |
exportednames = names(smodule) | |
cache = Dict{Symbol,Any}() | |
for name in allnames | |
!isdefined(smodule, name) && continue | |
sym = getfield(smodule, name) | |
if isa(sym, Function) | |
locations = map(methods(sym).ms) do m | |
(filename, line) = functionloc(m) | |
@static if is_windows() | |
filename_norm = normpath(filename) | |
filename_norm = replace(filename_norm, '\\', '/') | |
filename_escaped = URIParser.escape(filename_norm) | |
uri = "file:///$filename_escaped" | |
else | |
uri = "file:$filename" | |
end | |
return Location(uri, line-1) | |
end | |
else | |
locations = nothing | |
end | |
cache[name] = (get_docs(sym), locations, name in exportednames, name in basenames) | |
end | |
return cache | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment