From 04949a380b368bb2cafb3e0faa5414966fbce95c Mon Sep 17 00:00:00 2001 From: fredrikekre Date: Wed, 31 Aug 2022 13:04:55 +0000 Subject: [PATCH] Format files using DocumentFormat --- docs/make.jl | 6 +- registryindexer/main.jl | 76 +++++++++---------- src/SymbolServer.jl | 21 ++--- src/faketypes.jl | 2 +- src/indexpackage.jl | 4 +- src/serialize.jl | 6 +- src/server.jl | 10 +-- src/symbols.jl | 75 ++++++++++-------- src/utils.jl | 56 +++++++------- test/runtests.jl | 29 +++---- test/testenv/dev/TableTraits/test/runtests.jl | 6 +- 11 files changed, 155 insertions(+), 136 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 8b144d45..032c2448 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,16 +7,16 @@ makedocs(; repo="https://github.com/julia-vscode/SymbolServer.jl/blob/{commit}{path}#L{line}", sitename="SymbolServer.jl", format=Documenter.HTML(; - prettyurls=prettyurls = get(ENV, "CI", nothing) == "true", + prettyurls=prettyurls = get(ENV, "CI", nothing) == "true" # canonical="https://www.julia-vscode.org/SymbolServer.jl", # assets=String[], ), pages=[ "Home" => "index.md", "Syntax Reference" => "syntax.md", - ], + ] ) deploydocs(; - repo="github.com/julia-vscode/SymbolServer.jl", + repo="github.com/julia-vscode/SymbolServer.jl" ) diff --git a/registryindexer/main.jl b/registryindexer/main.jl index c051a1fa..5e9b7aeb 100644 --- a/registryindexer/main.jl +++ b/registryindexer/main.jl @@ -2,7 +2,7 @@ max_n = 1_000_000 max_versions = 1_000_000 -max_tasks = length(ARGS)>1 ? parse(Int, ARGS[2]) : 1 +max_tasks = length(ARGS) > 1 ? parse(Int, ARGS[2]) : 1 julia_versions = [v"1.7.2"] @@ -13,26 +13,26 @@ Pkg.instantiate() using ProgressMeter, Query, JSON, UUIDs, Tar, CodecZlib -function get_all_package_versions(;max_versions=typemax(Int)) +function get_all_package_versions(; max_versions=typemax(Int)) registry_folder_path = joinpath(homedir(), ".julia", "registries", "General") registry_path = joinpath(registry_folder_path, "Registry.toml") registry_content = Pkg.TOML.parsefile(registry_path) packages = registry_content["packages"] |> - @map({ - name = _[2]["name"], - uuid = UUID(_[1]), - path = _[2]["path"] - }) |> - @mutate( - versions = (Pkg.TOML.parsefile(joinpath(registry_folder_path, _.path, "Versions.toml")) |> - @map(i->{version=VersionNumber(i[1]), treehash=i[2]["git-tree-sha1"]}) |> - @orderby_descending(i->i.version) |> - @take(max_versions) |> - collect) - ) |> - collect + @map({ + name = _[2]["name"], + uuid = UUID(_[1]), + path = _[2]["path"] + }) |> + @mutate( + versions = (Pkg.TOML.parsefile(joinpath(registry_folder_path, _.path, "Versions.toml")) |> + @map(i -> {version = VersionNumber(i[1]), treehash = i[2]["git-tree-sha1"]}) |> + @orderby_descending(i -> i.version) |> + @take(max_versions) |> + collect) + ) |> + collect return packages end @@ -42,7 +42,7 @@ function get_flattened_package_versions(packages) for p in packages for v in p.versions - push!(flattened_packageversions, (;p.name, p.uuid, p.path, version=v.version, treehash=v.treehash)) + push!(flattened_packageversions, (; p.name, p.uuid, p.path, version=v.version, treehash=v.treehash)) end end @@ -54,11 +54,11 @@ function execute(cmd::Base.Cmd) err = IOBuffer() process = run(pipeline(ignorestatus(cmd), stdout=out, stderr=err)) - out_string =String(take!(out)) + out_string = String(take!(out)) err_string = String(take!(err)) - return (stdout = out_string, - stderr = err_string, - code = process.exitcode) + return (stdout=out_string, + stderr=err_string, + code=process.exitcode) end @info "Indexing started..." @@ -69,7 +69,7 @@ flattened_packageversions = get_flattened_package_versions(all_packages) @info "Loaded package versions from registry..." -cache_folder = length(ARGS)>0 ? ARGS[1] : joinpath(@__DIR__, "..", "registryindexcache") +cache_folder = length(ARGS) > 0 ? ARGS[1] : joinpath(@__DIR__, "..", "registryindexcache") @info "Using the following folder as the cache folder: " cache_folder @@ -92,7 +92,7 @@ asyncmap(julia_versions) do v print(f, res.stderr) end - if res.code!=0 + if res.code != 0 error("Could not create docker image.") end end @@ -108,10 +108,10 @@ true || asyncmap(julia_versions) do v else res = execute(`docker run --rm --mount type=bind,source="$cache_folder",target=/symcache juliavscodesymbolindexer:$v julia SymbolServer/src/indexbasestdlib.jl $v`) - if res.code==10 || res.code==20 - if res.code==10 + if res.code == 10 || res.code == 20 + if res.code == 10 # global count_failed_to_load += 1 - elseif res.code==20 + elseif res.code == 20 # global count_failed_to_install += 1 end @@ -121,7 +121,7 @@ true || asyncmap(julia_versions) do v # # Write them to a file # open(joinpath(path, error_filename), "w") do io # end - + # Pkg.PlatformEngines.package(path, cache_path) # end @@ -136,7 +136,7 @@ true || asyncmap(julia_versions) do v # global status_db # push!(status_db, Dict("name"=>v.name, "uuid"=>string(v.uuid), "version"=>string(v.version), "treehash"=>v.treehash, "status"=>res.code==20 ? "install_error" : "load_error", "indexattempts"=>[Dict("juliaversion"=>string(VERSION), "stdout"=>res.stdout, "stderr"=>res.stderr)])) - elseif res.code==0 + elseif res.code == 0 # global count_successfully_cached += 1 else # global count_failed_to_index += 1 @@ -154,7 +154,7 @@ end @info "Now computing which of the total $(length(flattened_packageversions)) package versions that exist still need to be indexed..." unindexed_packageversions = filter(collect(Iterators.take(flattened_packageversions, max_n))) do v - versionwithoutplus = replace(string(v.version), '+'=>'_') + versionwithoutplus = replace(string(v.version), '+' => '_') cache_path = joinpath(cache_folder, "v1", "packages", string(uppercase(v.name[1])), "$(v.name)_$(v.uuid)", "v$(versionwithoutplus)_$(v.treehash).tar.gz") @@ -179,7 +179,7 @@ status_db = isfile(statusdb_filename) ? JSON.parsefile(statusdb_filename) : [] @info "Starting the actual indexing process..." asyncmap(unindexed_packageversions, ntasks=max_tasks) do v - versionwithoutplus = replace(string(v.version), '+'=>'_') + versionwithoutplus = replace(string(v.version), '+' => '_') cache_path = joinpath(cache_folder, "v1", "packages", string(uppercase(v.name[1])), "$(v.name)_$(v.uuid)") mkpath(cache_path) @@ -188,12 +188,12 @@ asyncmap(unindexed_packageversions, ntasks=max_tasks) do v mktempdir() do path res = execute(`docker run --rm --mount type=bind,source="$path",target=/symcache juliavscodesymbolindexer:$(first(julia_versions)) julia SymbolServer/src/indexpackage.jl $(v.name) $(v.version) $(v.uuid) $(v.treehash)`) - if res.code==37 # This is our magic error code that indicates everything worked + if res.code == 37 # This is our magic error code that indicates everything worked global count_successfully_cached += 1 else - if res.code==10 + if res.code == 10 global count_failed_to_load += 1 - elseif res.code==20 + elseif res.code == 20 global count_failed_to_install += 1 else global count_failed_to_index += 1 @@ -209,20 +209,20 @@ asyncmap(unindexed_packageversions, ntasks=max_tasks) do v isfile(joinpath(path, error_filename)) && rm(joinpath(path, error_filename)) # Write them to a file - open(joinpath(path, error_filename), "w") do io + open(joinpath(path, error_filename), "w") do io end - open(joinpath(cache_folder, "logs", res.code==10 ? "packageloadfailure" : res.code==20 ? "packageinstallfailure" : "packageindexfailure", "log_$(v.name)_v$(versionwithoutplus)_stdout.txt"), "w") do f + open(joinpath(cache_folder, "logs", res.code == 10 ? "packageloadfailure" : res.code == 20 ? "packageinstallfailure" : "packageindexfailure", "log_$(v.name)_v$(versionwithoutplus)_stdout.txt"), "w") do f print(f, res.stdout) end - open(joinpath(cache_folder, "logs", res.code==10 ? "packageloadfailure" : res.code==20 ? "packageinstallfailure" : "packageindexfailure", "log_$(v.name)_v$(versionwithoutplus)_stderr.txt"), "w") do f + open(joinpath(cache_folder, "logs", res.code == 10 ? "packageloadfailure" : res.code == 20 ? "packageinstallfailure" : "packageindexfailure", "log_$(v.name)_v$(versionwithoutplus)_stderr.txt"), "w") do f print(f, res.stderr) end global status_db - push!(status_db, Dict("name"=>v.name, "uuid"=>string(v.uuid), "version"=>string(v.version), "treehash"=>v.treehash, "status"=>res.code==20 ? "install_error" : res.code==10 ? "load_error" : "index_error", "indexattempts"=>[Dict("juliaversion"=>string(VERSION), "stdout"=>res.stdout, "stderr"=>res.stderr)])) + push!(status_db, Dict("name" => v.name, "uuid" => string(v.uuid), "version" => string(v.version), "treehash" => v.treehash, "status" => res.code == 20 ? "install_error" : res.code == 10 ? "load_error" : "index_error", "indexattempts" => [Dict("juliaversion" => string(VERSION), "stdout" => res.stdout, "stderr" => res.stderr)])) end # @info "Files to be compressed" path readdir(path, join=true) ispath(cache_path) isfile(cache_path_compressed) @@ -237,8 +237,8 @@ asyncmap(unindexed_packageversions, ntasks=max_tasks) do v end end - next!(p, showvalues = [ - (:finished_package_count,p.counter+1), + next!(p, showvalues=[ + (:finished_package_count, p.counter + 1), (:count_successfully_cached, count_successfully_cached), (:count_failed_to_install, count_failed_to_install), (:count_failed_to_load, count_failed_to_load), diff --git a/src/SymbolServer.jl b/src/SymbolServer.jl index ffb56a73..55842aed 100644 --- a/src/SymbolServer.jl +++ b/src/SymbolServer.jl @@ -19,7 +19,7 @@ mutable struct SymbolServerInstance store_path::String symbolcache_upstream::String - function SymbolServerInstance(depot_path::String="", store_path::Union{String,Nothing}=nothing; symbolcache_upstream = nothing) + function SymbolServerInstance(depot_path::String="", store_path::Union{String,Nothing}=nothing; symbolcache_upstream=nothing) if symbolcache_upstream === nothing symbolcache_upstream = "https://www.julia-vscode.org/symbolcache" end @@ -27,7 +27,7 @@ mutable struct SymbolServerInstance end end -function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, progress_callback=nothing, error_handler=nothing; download = false) +function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, progress_callback=nothing, error_handler=nothing; download=false) !ispath(environment_path) && return :success, recursive_copy(stdlibs) # see if we can download any package cache's before @@ -42,9 +42,9 @@ function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, p if manifest !== nothing @debug "Downloading cache files for manifest at $(manifest_filename)." to_download = collect(validate_disc_store(ssi.store_path, manifest)) - batches = Iterators.partition(to_download, max(1, floor(Int, length(to_download)÷50))) + batches = Iterators.partition(to_download, max(1, floor(Int, length(to_download) ÷ 50))) for (i, batch) in enumerate(batches) - percentage = round(Int, 100*(i - 1)/length(batches)) + percentage = round(Int, 100 * (i - 1) / length(batches)) progress_callback !== nothing && progress_callback("Downloading caches...", percentage) @sync for pkg in batch @async begin @@ -131,7 +131,7 @@ function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, p end end take!(server_is_ready) - p = open(pipeline(Cmd(`$jl_cmd --code-coverage=$(use_code_coverage==0 ? "none" : "user") --startup-file=no --compiled-modules=no --history-file=no --project=$environment_path $server_script $(ssi.store_path) $pipename`, env=env_to_use), stderr=stderr_for_client_process), read=true, write=true) + p = open(pipeline(Cmd(`$jl_cmd --code-coverage=$(use_code_coverage==0 ? "none" : "user") --startup-file=no --compiled-modules=no --history-file=no --project=$environment_path $server_script $(ssi.store_path) $pipename`, env=env_to_use), stderr=stderr_for_client_process), read=true, write=true) ssi.process = p yield() @@ -150,7 +150,7 @@ function getstore(ssi::SymbolServerInstance, environment_path::AbstractString, p else @debug "SymbolStore: store failure" if currently_loading_a_package - return :package_load_crash, (package_name = current_package_name, stderr = stderr_for_client_process) + return :package_load_crash, (package_name=current_package_name, stderr=stderr_for_client_process) else return :failure, stderr_for_client_process end @@ -171,7 +171,8 @@ function pipe_name() # Try to use /tmp and if that fails, hope the long pipe name works anyway maybe = "/tmp/" * prefix * uuid try - touch(maybe); rm(maybe) # Check permissions on this path + touch(maybe) + rm(maybe) # Check permissions on this path pipename = maybe catch end @@ -179,7 +180,7 @@ function pipe_name() return pipename end -function load_project_packages_into_store!(ssi::SymbolServerInstance, environment_path, store, progress_callback = nothing) +function load_project_packages_into_store!(ssi::SymbolServerInstance, environment_path, store, progress_callback=nothing) project_filename = isfile(joinpath(environment_path, "JuliaProject.toml")) ? joinpath(environment_path, "JuliaProject.toml") : joinpath(environment_path, "Project.toml") project = try Pkg.API.read_project(project_filename) @@ -203,7 +204,7 @@ end Tries to load the on-disc stored cache for a package (uuid). Attempts to generate (and save to disc) a new cache if the file does not exist or is unopenable. """ -function load_package_from_cache_into_store!(ssi::SymbolServerInstance, uuid::UUID, environment_path, manifest, store, progress_callback = nothing, percentage = missing) +function load_package_from_cache_into_store!(ssi::SymbolServerInstance, uuid::UUID, environment_path, manifest, store, progress_callback=nothing, percentage=missing) yield() isinmanifest(manifest, uuid) || return pe = frommanifest(manifest, uuid) @@ -252,7 +253,7 @@ end function clear_disc_store(ssi::SymbolServerInstance) for f in readdir(ssi.store_path) if occursin(f, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") - rm(joinpath(ssi.store_path, f), recursive = true) + rm(joinpath(ssi.store_path, f), recursive=true) end end end diff --git a/src/faketypes.jl b/src/faketypes.jl index 197c6121..2c2ae862 100644 --- a/src/faketypes.jl +++ b/src/faketypes.jl @@ -88,7 +88,7 @@ function Base.print(io::IO, tn::FakeTypeName) end Base.print(io::IO, x::FakeUnionAll) = print(io, x.body, " where ", x.var) function Base.print(io::IO, x::FakeUnion; inunion=false) - !inunion && print(io, "Union{") + !inunion && print(io, "Union{") print(io, x.a, ",") if x.b isa FakeUnion print(io, x.b, inunion=true) diff --git a/src/indexpackage.jl b/src/indexpackage.jl index 421a0bf4..2fc690db 100644 --- a/src/indexpackage.jl +++ b/src/indexpackage.jl @@ -13,7 +13,7 @@ current_package_treehash = ARGS[4] # This path will always be mounted in the docker container in which we are running store_path = "/symcache" -current_package_versionwithoutplus = replace(string(current_package_version), '+'=>'_') +current_package_versionwithoutplus = replace(string(current_package_version), '+' => '_') filename_with_extension = "v$(current_package_versionwithoutplus)_$current_package_treehash.jstore" module LoadingBay end @@ -45,7 +45,7 @@ end env = getenvtree([current_package_name]) symbols(env, m, get_return_type=true) - # Strip out paths +# Strip out paths modify_dirs(env[current_package_name], f -> modify_dir(f, pkg_src_dir(Base.loaded_modules[Base.PkgId(current_package_uuid, string(current_package_name))]), "PLACEHOLDER")) # There's an issue here - @enum used within CSTParser seems to add a method that is introduced from Enums.jl... diff --git a/src/serialize.jl b/src/serialize.jl index 5568a9fb..fd918237 100644 --- a/src/serialize.jl +++ b/src/serialize.jl @@ -169,7 +169,7 @@ function write_vector(io, x) end end -function read(io, t = Base.read(io, UInt8)) +function read(io, t=Base.read(io, UInt8)) # There are a bunch of `yield`s in potentially expensive code paths. # One top-level `yield` would probably increase responsiveness in the # LS, but increases runtime by 3x. This seems like a good compromise. @@ -221,7 +221,7 @@ function read(io, t = Base.read(io, UInt8)) file = read(io) line = Base.read(io, UInt32) nsig = Base.read(io, Int) - sig = Vector{Pair{Any, Any}}(undef, nsig) + sig = Vector{Pair{Any,Any}}(undef, nsig) for i in 1:nsig sig[i] = read(io) => read(io) end @@ -259,7 +259,7 @@ function read(io, t = Base.read(io, UInt8)) false elseif t === TupleHeader N = Base.read(io, Int) - ntuple(i->read(io), N) + ntuple(i -> read(io), N) elseif t === PackageHeader yield() name = read(io) diff --git a/src/server.jl b/src/server.jl index 0d082922..0e1f59ec 100644 --- a/src/server.jl +++ b/src/server.jl @@ -93,7 +93,7 @@ visited = Base.IdSet{Module}([Base, Core]) # Load all packages together for (i, uuid) in enumerate(packages_to_load) - load_package(ctx, uuid, conn, LoadingBay, round(Int, 100*(i - 1)/length(packages_to_load))) + load_package(ctx, uuid, conn, LoadingBay, round(Int, 100 * (i - 1) / length(packages_to_load))) # XXX: The following *may* duplicate some work, but we want to make sure that interrupts of # the SymbolServer process don't invalidate *all* work done (which would happen when only @@ -104,12 +104,12 @@ for (i, uuid) in enumerate(packages_to_load) # Populate the above with symbols, skipping modules that don't need caching. # symbols (env_symbols) - # don't need to cache these each time... + # don't need to cache these each time... for (pid, m) in Base.loaded_modules if pid.uuid !== nothing && - is_stdlib(pid.uuid) && - isinmanifest(ctx, pid.uuid) && - isfile(joinpath(server.storedir, SymbolServer.get_cache_path(manifest(ctx), pid.uuid)...)) + is_stdlib(pid.uuid) && + isinmanifest(ctx, pid.uuid) && + isfile(joinpath(server.storedir, SymbolServer.get_cache_path(manifest(ctx), pid.uuid)...)) push!(visited, m) delete!(env_symbols, Symbol(pid.name)) end diff --git a/src/symbols.jl b/src/symbols.jl index f6acf0cc..6d02cace 100644 --- a/src/symbols.jl +++ b/src/symbols.jl @@ -112,7 +112,12 @@ function maybe_fix_path(file) return maybe_fixup_stdlib_path(file) end -safe_isfile(x) = try isfile(x); catch; false end +safe_isfile(x) = + try + isfile(x) + catch + false + end const BUILDBOT_STDLIB_PATH = dirname(abspath(joinpath(String((@which versioninfo()).file), "..", "..", ".."))) replace_buildbot_stdlibpath(str::String) = replace(str, BUILDBOT_STDLIB_PATH => Sys.STDLIB) """ @@ -134,7 +139,7 @@ function maybe_fixup_stdlib_path(path) end const _global_method_cache = IdDict{Any,Vector{Any}}() -function methodinfo(@nospecialize(f); types = Tuple, world = typemax(UInt)) +function methodinfo(@nospecialize(f); types=Tuple, world=typemax(UInt)) key = (f, types, world) cached = get(_global_method_cache, key, nothing) if cached === nothing @@ -167,7 +172,7 @@ function cache_methods(@nospecialize(f), name, env, get_return_type) world = typemax(UInt) ms = Tuple{Module,MethodStore}[] methods0 = try - methodinfo(f; types = types, world = world) + methodinfo(f; types=types, world=world) catch err return ms end @@ -177,12 +182,12 @@ function cache_methods(@nospecialize(f), name, env, get_return_type) # Get inferred method return type if get_return_type sparams = Core.svec(sparam_syms(m[3])...) - rt = try + rt = try @static if isdefined(Core.Compiler, :NativeInterpreter) - Core.Compiler.typeinf_type(Core.Compiler.NativeInterpreter(), m[3], m[3].sig, sparams) - else - Core.Compiler.typeinf_type(m[3], m[3].sig, sparams, Core.Compiler.Params(world)) - end + Core.Compiler.typeinf_type(Core.Compiler.NativeInterpreter(), m[3], m[3].sig, sparams) + else + Core.Compiler.typeinf_type(m[3], m[3].sig, sparams, Core.Compiler.Params(world)) + end catch e Any end @@ -254,10 +259,10 @@ else end end -function apply_to_everything(f, m = nothing, visited = Base.IdSet{Module}()) +function apply_to_everything(f, m=nothing, visited=Base.IdSet{Module}()) if m isa Module push!(visited, m) - for s in unsorted_names(m, all = true, imported = true) + for s in unsorted_names(m, all=true, imported=true) (!isdefined(m, s) || s == nameof(m)) && continue x = getfield(m, s) f(x) @@ -274,11 +279,11 @@ end -function oneverything(f, m = nothing, visited = Base.IdSet{Module}()) +function oneverything(f, m=nothing, visited=Base.IdSet{Module}()) if m isa Module push!(visited, m) state = nothing - for s in unsorted_names(m, all = true, imported = true) + for s in unsorted_names(m, all=true, imported=true) !isdefined(m, s) && continue x = getfield(m, s) state = f(m, s, x, state) @@ -294,7 +299,7 @@ function oneverything(f, m = nothing, visited = Base.IdSet{Module}()) end const _global_symbol_cache_by_mod = IdDict{Module,Base.IdSet{Symbol}}() -function build_namecache(m, s, @nospecialize(x), state::Union{Base.IdSet{Symbol},Nothing} = nothing) +function build_namecache(m, s, @nospecialize(x), state::Union{Base.IdSet{Symbol},Nothing}=nothing) if state === nothing state = get(_global_symbol_cache_by_mod, m, nothing) if state === nothing @@ -344,10 +349,10 @@ end usedby(outer, inner) = outer !== inner && isdefined(outer, nameof(inner)) && getproperty(outer, nameof(inner)) === inner && all(isdefined(outer, name) || !isdefined(inner, name) for name in unsorted_names(inner)) istoplevelmodule(m) = parentmodule(m) === m || parentmodule(m) === Main -function getmoduletree(m::Module, amn, visited = Base.IdSet{Module}()) +function getmoduletree(m::Module, amn, visited=Base.IdSet{Module}()) push!(visited, m) cache = ModuleStore(m) - for s in unsorted_names(m, all = true, imported = true) + for s in unsorted_names(m, all=true, imported=true) !isdefined(m, s) && continue x = getfield(m, s) if x isa Module @@ -376,16 +381,16 @@ function getmoduletree(m::Module, amn, visited = Base.IdSet{Module}()) cache end -function getenvtree(names = nothing) +function getenvtree(names=nothing) amn = allmodulenames() EnvStore(nameof(m) => getmoduletree(m, amn) for m in Base.loaded_modules_array() if names === nothing || nameof(m) in names) end # faster and more correct split_module_names all_names(m) = all_names(m, x -> isdefined(m, x)) -function all_names(m, pred, symbols = Set(Symbol[]), seen = Set(Module[])) +function all_names(m, pred, symbols=Set(Symbol[]), seen=Set(Module[])) push!(seen, m) - ns = unsorted_names(m; all = true, imported = false) + ns = unsorted_names(m; all=true, imported=false) for n in ns isdefined(m, n) || continue Base.isdeprecated(m, n) && continue @@ -400,7 +405,7 @@ function all_names(m, pred, symbols = Set(Symbol[]), seen = Set(Module[])) symbols end -function symbols(env::EnvStore, m::Union{Module,Nothing} = nothing, allnames::Base.IdSet{Symbol} = getallns(), visited = Base.IdSet{Module}(); get_return_type = false) +function symbols(env::EnvStore, m::Union{Module,Nothing}=nothing, allnames::Base.IdSet{Symbol}=getallns(), visited=Base.IdSet{Module}(); get_return_type=false) if m isa Module cache = _lookup(VarRef(m), env, true) cache === nothing && return @@ -450,7 +455,7 @@ function symbols(env::EnvStore, m::Union{Module,Nothing} = nothing, allnames::Ba if x === m cache[s] = VarRef(x) elseif parentmodule(x) === m - symbols(env, x, allnames, visited, get_return_type = get_return_type) + symbols(env, x, allnames, visited, get_return_type=get_return_type) else cache[s] = VarRef(x) end @@ -460,16 +465,16 @@ function symbols(env::EnvStore, m::Union{Module,Nothing} = nothing, allnames::Ba end else for m in Base.loaded_modules_array() - in(m, visited) || symbols(env, m, allnames, visited, get_return_type = get_return_type) + in(m, visited) || symbols(env, m, allnames, visited, get_return_type=get_return_type) end end end -function load_core(; get_return_type = false) +function load_core(; get_return_type=false) c = Pkg.Types.Context() - cache = getenvtree([:Core,:Base]) - symbols(cache, get_return_type = get_return_type) + cache = getenvtree([:Core, :Base]) + symbols(cache, get_return_type=get_return_type) cache[:Main] = ModuleStore(VarRef(nothing, :Main), Dict(), "", true, [], []) # This is wrong. As per the docs the Base.include each module should have it's own @@ -484,7 +489,7 @@ function load_core(; get_return_type = false) cache[:Base][Symbol("@.")] = cache[:Base][Symbol("@__dot__")] cache[:Core][:Main] = GenericStore(VarRef(nothing, :Main), FakeTypeName(Module), _doc(Base.Docs.Binding(Main, :Main)), true) # Add built-ins - builtins = Symbol[nameof(getfield(Core, n).instance) for n in unsorted_names(Core, all = true) if isdefined(Core, n) && getfield(Core, n) isa DataType && isdefined(getfield(Core, n), :instance) && getfield(Core, n).instance isa Core.Builtin] + builtins = Symbol[nameof(getfield(Core, n).instance) for n in unsorted_names(Core, all=true) if isdefined(Core, n) && getfield(Core, n) isa DataType && isdefined(getfield(Core, n), :instance) && getfield(Core, n).instance isa Core.Builtin] cnames = unsorted_names(Core) for f in builtins if !haskey(cache[:Core], f) @@ -515,7 +520,7 @@ function load_core(; get_return_type = false) push!(cache[:Core][:fieldtype].methods, MethodStore(:fieldtype, :Core, "built-in", 0, [:t => FakeTypeName(DataType), :field => FakeTypeName(Symbol)], Symbol[], FakeTypeName(Type{T} where T))) push!(cache[:Core][:getfield].methods, MethodStore(:setfield, :Core, "built-in", 0, [:object => FakeTypeName(Any), :item => FakeTypeName(Any)], Symbol[], FakeTypeName(Any))) push!(cache[:Core][:ifelse].methods, MethodStore(:ifelse, :Core, "built-in", 0, [:condition => FakeTypeName(Bool), :x => FakeTypeName(Any), :y => FakeTypeName(Any)], Symbol[], FakeTypeName(Any))) - push!(cache[:Core][:invoke].methods, MethodStore(:invoke, :Core, "built-in", 0, [:f => FakeTypeName(Function), :x => FakeTypeName(Any), :argtypes => FakeTypeName(Type{T} where T) , :args => FakeTypeName(Vararg{Any})], Symbol[], FakeTypeName(Any))) + push!(cache[:Core][:invoke].methods, MethodStore(:invoke, :Core, "built-in", 0, [:f => FakeTypeName(Function), :x => FakeTypeName(Any), :argtypes => FakeTypeName(Type{T} where T), :args => FakeTypeName(Vararg{Any})], Symbol[], FakeTypeName(Any))) push!(cache[:Core][:isa].methods, MethodStore(:isa, :Core, "built-in", 0, [:a => FakeTypeName(Any), :T => FakeTypeName(Type{T} where T)], Symbol[], FakeTypeName(Bool))) push!(cache[:Core][:isdefined].methods, MethodStore(:getproperty, :Core, "built-in", 0, [:value => FakeTypeName(Any), :field => FakeTypeName(Any)], Symbol[], FakeTypeName(Any))) push!(cache[:Core][:nfields].methods, MethodStore(:nfields, :Core, "built-in", 0, [:x => FakeTypeName(Any)], Symbol[], FakeTypeName(Int))) @@ -579,7 +584,7 @@ function load_core(; get_return_type = false) end -function collect_extended_methods(depot::EnvStore, extendeds = Dict{VarRef,Vector{VarRef}}()) +function collect_extended_methods(depot::EnvStore, extendeds=Dict{VarRef,Vector{VarRef}}()) for m in depot collect_extended_methods(m[2], extendeds, m[2].name) end @@ -596,7 +601,11 @@ function collect_extended_methods(mod::ModuleStore, extendeds, mname) end end -getallns() = let allns = Base.IdSet{Symbol}(); oneverything((m, s, x, state) -> push!(allns, s)); allns end +getallns() = + let allns = Base.IdSet{Symbol}() + oneverything((m, s, x, state) -> push!(allns, s)) + allns + end """ split_module_names(m::Module, allns) @@ -627,5 +636,11 @@ function split_module_names(m::Module, allns) internal_names, availablenames end -get_all_modules() = let allms = Base.IdSet{Module}(); apply_to_everything(x -> if x isa Module push!(allms, x) end); allms end -get_used_modules(M, allms = get_all_modules()) = [m for m in allms if usedby(M, m)] +get_all_modules() = + let allms = Base.IdSet{Module}() + apply_to_everything(x -> if x isa Module + push!(allms, x) + end) + allms + end +get_used_modules(M, allms=get_all_modules()) = [m for m in allms if usedby(M, m)] diff --git a/src/utils.jl b/src/utils.jl index 9663c288..fc2f14ac 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -40,7 +40,7 @@ function read_manifest(manifest_filename) return m.deps end catch err - @warn "Could not load manifest." exception=(err, catch_backtrace()) + @warn "Could not load manifest." exception = (err, catch_backtrace()) return nothing end end @@ -195,7 +195,7 @@ function _doc(binding::Base.Docs.Binding) result === nothing || return string(result) end results, groups = Base.Docs.DocStr[], Base.Docs.MultiDoc[] - # Lookup `binding` and `sig` for matches in all modules of the docsystem. + # Lookup `binding` and `sig` for matches in all modules of the docsystem. for mod in Base.Docs.modules dict = Base.Docs.meta(mod)::IdDict{Any,Any} if haskey(dict, binding) @@ -387,40 +387,40 @@ recursive_copy(ua::FakeUnionAll) = FakeUnionAll(recursive_copy(ua.var), recursiv end recursive_copy(m::ModuleStore) = ModuleStore(recursive_copy(m.name), recursive_copy(m.vals), m.doc, - m.exported, copy(m.exportednames), copy(m.used_modules)) + m.exported, copy(m.exportednames), copy(m.used_modules)) recursive_copy(p::Package) = Package(p.name, - recursive_copy(p.val), - p.uuid, - recursive_copy(p.sha)) + recursive_copy(p.val), + p.uuid, + recursive_copy(p.sha)) recursive_copy(ms::MethodStore) = MethodStore(ms.name, - ms.mod, - ms.file, - ms.line, - recursive_copy(ms.sig), - copy(ms.kws), - recursive_copy(ms.rt)) + ms.mod, + ms.file, + ms.line, + recursive_copy(ms.sig), + copy(ms.kws), + recursive_copy(ms.rt)) recursive_copy(dts::DataTypeStore) = DataTypeStore(recursive_copy(dts.name), - recursive_copy(dts.super), - recursive_copy(dts.parameters), - recursive_copy(dts.types), - recursive_copy(dts.fieldnames), - recursive_copy(dts.methods), - dts.doc, - dts.exported) + recursive_copy(dts.super), + recursive_copy(dts.parameters), + recursive_copy(dts.types), + recursive_copy(dts.fieldnames), + recursive_copy(dts.methods), + dts.doc, + dts.exported) recursive_copy(fs::FunctionStore) = FunctionStore(recursive_copy(fs.name), - recursive_copy(fs.methods), - fs.doc, - recursive_copy(fs.extends), - fs.exported) + recursive_copy(fs.methods), + fs.doc, + recursive_copy(fs.extends), + fs.exported) recursive_copy(gs::GenericStore) = GenericStore(recursive_copy(gs.name), - recursive_copy(gs.typ), - gs.doc, - gs.exported) + recursive_copy(gs.typ), + gs.doc, + gs.exported) # Tools for modifying source location @@ -614,7 +614,7 @@ function get_pkg_path(pkg::Base.PkgId, env, depot_path) return nothing end -function load_package(c::Pkg.Types.Context, uuid, conn, loadingbay, percentage = missing) +function load_package(c::Pkg.Types.Context, uuid, conn, loadingbay, percentage=missing) isinmanifest(c, uuid isa String ? Base.UUID(uuid) : uuid) || return pe_name = packagename(c, uuid) @@ -654,7 +654,7 @@ function get_cache_path(manifest, uuid) pkg_info = frommanifest(manifest, uuid) ver = version(pkg_info) ver = ver === nothing ? "nothing" : ver - ver = replace(string(ver), '+'=>'_') + ver = replace(string(ver), '+' => '_') th = tree_hash(pkg_info) th = th === nothing ? "nothing" : th diff --git a/test/runtests.jl b/test/runtests.jl index 118ba020..d1e907fd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using SymbolServer, Pkg using SymbolServer: packagename, packageuuid, deps, manifest, project, version, Package, frommanifest, VarRef, _lookup -using Base:UUID +using Base: UUID using Test allns = SymbolServer.getallns() @@ -102,7 +102,7 @@ end ssi = SymbolServerInstance("", store_path) @async begin - ret_status, store = getstore(ssi, path, download = false) + ret_status, store = getstore(ssi, path, download=false) @test ret_status == :canceled end @@ -111,7 +111,7 @@ end # previously gets run first sleep(1) - ret_status2, store2 = getstore(ssi, path, download = false) + ret_status2, store2 = getstore(ssi, path, download=false) if ret_status2 == :failure @info String(take!(store2)) @@ -175,23 +175,26 @@ import UUIDs else tmp_access = try n = "/tmp/" * string(UUIDs.uuid4()) - touch(n); rm(n) + touch(n) + rm(n) true catch false end too_long = joinpath(tempdir(), string(UUIDs.uuid4())^3) mkdir(too_long) - for TEMPDIR in (tempdir(), too_long); withenv("TEMPDIR" => TEMPDIR) do - p = SymbolServer.pipe_name() - # TEMPDIR + / + prefix + UUID[1:13] - if length(tempdir()) + 1 + length("vscjlsymserv-") + 13 < 92 || !tmp_access - @test startswith(p, tempdir()) - @test occursin(r"^vscjlsymserv-\w{8}-\w{4}$", basename(p)) - else - @test occursin(r"^/tmp/vscjlsymserv-\w{8}(?:-\w{4}){3}-\w{12}$", p) + for TEMPDIR in (tempdir(), too_long) + withenv("TEMPDIR" => TEMPDIR) do + p = SymbolServer.pipe_name() + # TEMPDIR + / + prefix + UUID[1:13] + if length(tempdir()) + 1 + length("vscjlsymserv-") + 13 < 92 || !tmp_access + @test startswith(p, tempdir()) + @test occursin(r"^vscjlsymserv-\w{8}-\w{4}$", basename(p)) + else + @test occursin(r"^/tmp/vscjlsymserv-\w{8}(?:-\w{4}){3}-\w{12}$", p) + end end - end end + end rm(too_long; recursive=true) end end diff --git a/test/testenv/dev/TableTraits/test/runtests.jl b/test/testenv/dev/TableTraits/test/runtests.jl index 62782681..8953085f 100644 --- a/test/testenv/dev/TableTraits/test/runtests.jl +++ b/test/testenv/dev/TableTraits/test/runtests.jl @@ -4,9 +4,9 @@ using Test @testset "TableTraits" begin - table_array = [(a = 1,), (a = 2,)] - any_table_array = Any[(a = 1,), (a = 2,)] - other_array = [1,2,3] + table_array = [(a=1,), (a=2,)] + any_table_array = Any[(a=1,), (a=2,)] + other_array = [1, 2, 3] without_eltype = (i for i in table_array) @test isiterabletable(table_array)