Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions src/SymbolServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function load_project_packages_into_store!(ssi::SymbolServerInstance, environmen
uuids = values(deps(project))
num_uuids = length(values(deps(project)))
for (i, uuid) in enumerate(uuids)
load_package_from_cache_into_store!(ssi, uuid, manifest, store, progress_callback, round(Int, 100*(i - 1)/num_uuids))
load_package_from_cache_into_store!(ssi, uuid isa UUID ? uuid : UUID(uuid), environment_path, manifest, store, progress_callback, round(Int, 100 * (i - 1) / num_uuids))
end
end

Expand All @@ -203,7 +203,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, 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)
Expand All @@ -219,9 +219,18 @@ function load_package_from_cache_into_store!(ssi::SymbolServerInstance, uuid, ma
package_data = open(cache_path) do io
CacheStore.read(io)
end

pkg_path = Base.locate_package(Base.PkgId(uuid, pe_name))
if pkg_path === nothing || !isfile(pkg_path)
pkg_path = get_pkg_path(Base.PkgId(uuid, pe_name), environment_path, ssi.depot_path)
end
if pkg_path !== nothing
modify_dirs(package_data.val, f -> modify_dir(f, r"^PLACEHOLDER", joinpath(pkg_path, "src")))
end

store[Symbol(pe_name)] = package_data.val
for dep in deps(pe)
load_package_from_cache_into_store!(ssi, packageuuid(dep), manifest, store, progress_callback, percentage)
load_package_from_cache_into_store!(ssi, packageuuid(dep), environment_path, manifest, store, progress_callback, percentage)
end
catch err
Base.display_error(stderr, err, catch_backtrace())
Expand Down
38 changes: 28 additions & 10 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
using Pkg

@static if VERSION < v"1.1"
const PackageEntry = Vector{Dict{String,Any}}
else
using Pkg.Types: PackageEntry
end

@static if isdefined(Base, :parsed_toml)
parsed_toml(args...) = Base.parsed_toml(args...)
else
parsed_toml(file) = Pkg.TOML.parsefile(file)
end

"""
manifest(c::Pkg.Types.Context)
Retrieves the UUID -> PackageEntry map from the manifest of a Context.
Expand Down Expand Up @@ -445,13 +453,13 @@ pkg_src_dir(m::Module) = dirname(pathof(m))
function modify_dir(f, s1, s2)
# @assert startswith(f, s1)
# Removed assertion because of Enums issue
string(s2, f[length(s1)+1:end])
replace(f, s1 => s2)
end


# tools to retrieve cache from the cloud

function get_file_from_cloud(manifest, uuid, environment_path, depot_dir, cache_dir = "../cache", download_dir = "../downloads/", symbolcache_upstream = "https://www.julia-vscode.org/symbolcache")
function get_file_from_cloud(manifest, uuid, environment_path, depot_dir, cache_dir="../cache", download_dir="../downloads/", symbolcache_upstream="https://www.julia-vscode.org/symbolcache")
paths = get_cache_path(manifest, uuid)
name = packagename(manifest, uuid)
link = string(first(splitext(join([symbolcache_upstream, "store/v1/packages", paths...], '/'))), ".tar.gz")
Expand Down Expand Up @@ -510,7 +518,7 @@ function get_file_from_cloud(manifest, uuid, environment_path, depot_dir, cache_
end

@debug "dirname" dirname(pkg_path)
modify_dirs(cache.val, f -> modify_dir(f, "PLACEHOLDER", joinpath(pkg_path, "src")))
modify_dirs(cache.val, f -> modify_dir(f, r"^PLACEHOLDER", joinpath(pkg_path, "src")))
open(file, "w") do io
CacheStore.write(io, cache)
end
Expand Down Expand Up @@ -556,27 +564,37 @@ function get_pkg_path(pkg::Base.PkgId, env, depot_path)
project_file isa Bool && return nothing
manifest_file = Base.project_file_manifest_path(project_file)

d = Base.parsed_toml(manifest_file)
entries = get(d, pkg.name, nothing)::Union{Nothing, Vector{Any}}
d = parsed_toml(manifest_file)
if get(d, "manifest_format", "0.0") == "2.0"
entries = get(d, "deps", nothing)
entries === nothing && return nothing
entries = map(e -> e[1], values(entries))
else
entries = get(d, pkg.name, nothing)
end
entries === nothing && return nothing # TODO: allow name to mismatch?
for entry in entries
entry = entry::Dict{String, Any}
uuid = get(entry, "uuid", nothing)::Union{Nothing, String}
entry = entry::Dict{String,Any}
uuid = get(entry, "uuid", nothing)::Union{Nothing,String}
uuid === nothing && continue
if UUID(uuid) === pkg.uuid
path = get(entry, "path", nothing)::Union{Nothing, String}
path = get(entry, "path", nothing)::Union{Nothing,String}
# this can only be true for explicitly dev'ed packages
if path !== nothing
path = normpath(abspath(dirname(manifest_file), path))
return path
end
hash = get(entry, "git-tree-sha1", nothing)::Union{Nothing, String}
hash = get(entry, "git-tree-sha1", nothing)::Union{Nothing,String}
hash === nothing && return nothing
hash = Base.SHA1(hash)
# empty default path probably means that we should use the default Julia depots
if depot_path == ""
depot_paths = []
Base.append_default_depot_path!(depot_paths)
if isdefined(Base, :append_default_depot_path!)
Base.append_default_depot_path!(depot_paths)
else
depot_paths = Pkg.depots()
end
else
depot_paths = [depot_path]
end
Expand Down