Skip to content

Commit 80edf77

Browse files
authored
Merge pull request #252 from julia-vscode/sp/manifest-compat-for-17
Fix path replacement for 1.7
2 parents edcf642 + cb50965 commit 80edf77

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

src/SymbolServer.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function load_project_packages_into_store!(ssi::SymbolServerInstance, environmen
194194
uuids = values(deps(project))
195195
num_uuids = length(values(deps(project)))
196196
for (i, uuid) in enumerate(uuids)
197-
load_package_from_cache_into_store!(ssi, uuid, manifest, store, progress_callback, round(Int, 100*(i - 1)/num_uuids))
197+
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))
198198
end
199199
end
200200

@@ -203,7 +203,7 @@ end
203203
204204
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.
205205
"""
206-
function load_package_from_cache_into_store!(ssi::SymbolServerInstance, uuid, manifest, store, progress_callback = nothing, percentage = missing)
206+
function load_package_from_cache_into_store!(ssi::SymbolServerInstance, uuid::UUID, environment_path, manifest, store, progress_callback = nothing, percentage = missing)
207207
yield()
208208
isinmanifest(manifest, uuid) || return
209209
pe = frommanifest(manifest, uuid)
@@ -219,9 +219,18 @@ function load_package_from_cache_into_store!(ssi::SymbolServerInstance, uuid, ma
219219
package_data = open(cache_path) do io
220220
CacheStore.read(io)
221221
end
222+
223+
pkg_path = Base.locate_package(Base.PkgId(uuid, pe_name))
224+
if pkg_path === nothing || !isfile(pkg_path)
225+
pkg_path = get_pkg_path(Base.PkgId(uuid, pe_name), environment_path, ssi.depot_path)
226+
end
227+
if pkg_path !== nothing
228+
modify_dirs(package_data.val, f -> modify_dir(f, r"^PLACEHOLDER", joinpath(pkg_path, "src")))
229+
end
230+
222231
store[Symbol(pe_name)] = package_data.val
223232
for dep in deps(pe)
224-
load_package_from_cache_into_store!(ssi, packageuuid(dep), manifest, store, progress_callback, percentage)
233+
load_package_from_cache_into_store!(ssi, packageuuid(dep), environment_path, manifest, store, progress_callback, percentage)
225234
end
226235
catch err
227236
Base.display_error(stderr, err, catch_backtrace())

src/utils.jl

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
using Pkg
2+
13
@static if VERSION < v"1.1"
24
const PackageEntry = Vector{Dict{String,Any}}
35
else
46
using Pkg.Types: PackageEntry
57
end
68

9+
@static if isdefined(Base, :parsed_toml)
10+
parsed_toml(args...) = Base.parsed_toml(args...)
11+
else
12+
parsed_toml(file) = Pkg.TOML.parsefile(file)
13+
end
14+
715
"""
816
manifest(c::Pkg.Types.Context)
917
Retrieves the UUID -> PackageEntry map from the manifest of a Context.
@@ -445,13 +453,13 @@ pkg_src_dir(m::Module) = dirname(pathof(m))
445453
function modify_dir(f, s1, s2)
446454
# @assert startswith(f, s1)
447455
# Removed assertion because of Enums issue
448-
string(s2, f[length(s1)+1:end])
456+
replace(f, s1 => s2)
449457
end
450458

451459

452460
# tools to retrieve cache from the cloud
453461

454-
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")
462+
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")
455463
paths = get_cache_path(manifest, uuid)
456464
name = packagename(manifest, uuid)
457465
link = string(first(splitext(join([symbolcache_upstream, "store/v1/packages", paths...], '/'))), ".tar.gz")
@@ -510,7 +518,7 @@ function get_file_from_cloud(manifest, uuid, environment_path, depot_dir, cache_
510518
end
511519

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

559-
d = Base.parsed_toml(manifest_file)
560-
entries = get(d, pkg.name, nothing)::Union{Nothing, Vector{Any}}
567+
d = parsed_toml(manifest_file)
568+
if get(d, "manifest_format", "0.0") == "2.0"
569+
entries = get(d, "deps", nothing)
570+
entries === nothing && return nothing
571+
entries = map(e -> e[1], values(entries))
572+
else
573+
entries = get(d, pkg.name, nothing)
574+
end
561575
entries === nothing && return nothing # TODO: allow name to mismatch?
562576
for entry in entries
563-
entry = entry::Dict{String, Any}
564-
uuid = get(entry, "uuid", nothing)::Union{Nothing, String}
577+
entry = entry::Dict{String,Any}
578+
uuid = get(entry, "uuid", nothing)::Union{Nothing,String}
565579
uuid === nothing && continue
566580
if UUID(uuid) === pkg.uuid
567-
path = get(entry, "path", nothing)::Union{Nothing, String}
581+
path = get(entry, "path", nothing)::Union{Nothing,String}
568582
# this can only be true for explicitly dev'ed packages
569583
if path !== nothing
570584
path = normpath(abspath(dirname(manifest_file), path))
571585
return path
572586
end
573-
hash = get(entry, "git-tree-sha1", nothing)::Union{Nothing, String}
587+
hash = get(entry, "git-tree-sha1", nothing)::Union{Nothing,String}
574588
hash === nothing && return nothing
575589
hash = Base.SHA1(hash)
576590
# empty default path probably means that we should use the default Julia depots
577591
if depot_path == ""
578592
depot_paths = []
579-
Base.append_default_depot_path!(depot_paths)
593+
if isdefined(Base, :append_default_depot_path!)
594+
Base.append_default_depot_path!(depot_paths)
595+
else
596+
depot_paths = Pkg.depots()
597+
end
580598
else
581599
depot_paths = [depot_path]
582600
end

0 commit comments

Comments
 (0)