Skip to content

Commit

Permalink
filter packages based on current julia version (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 11, 2019
1 parent 3748446 commit ec9e5cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
34 changes: 23 additions & 11 deletions stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using UUIDs
import REPL
import REPL: LineEdit, REPLCompletions

import ..devdir, ..Types.casesensitive_isdir
import ..devdir, ..Types.casesensitive_isdir, ..TOML
using ..Types, ..Display, ..Operations, ..API

############
Expand Down Expand Up @@ -896,18 +896,30 @@ function complete_installed_package(s, i1, i2, project_opt)
end

function complete_remote_package(s, i1, i2)
cmp = filter(cmd -> startswith(cmd, s), collect_package_names())
return cmp, i1:i2, !isempty(cmp)
end

function collect_package_names()
r = r"name = \"(.*?)\""
names = String[]
cmp = String[]
julia_version = VERSION
for reg in Types.registries(;clone_default=false)
regcontent = read(joinpath(reg, "Registry.toml"), String)
append!(names, collect(match.captures[1] for match in eachmatch(r, regcontent)))
data = TOML.parsefile(joinpath(reg, "Registry.toml"))
for (uuid, pkginfo) in data["packages"]
name = pkginfo["name"]
if startswith(name, s)
compat_data = Operations.load_package_data_raw(
VersionSpec, joinpath(reg, pkginfo["path"], "Compat.toml"))
supported_julia_versions = VersionSpec(VersionRange[])
for (ver_range, compats) in compat_data
for (compat, v) in compats
if compat == "julia"
union!(supported_julia_versions, VersionSpec(v))
end
end
end
if VERSION in supported_julia_versions
push!(cmp, name)
end
end
end
end
return sort!(names)
return cmp, i1:i2, !isempty(cmp)
end

function completions(full, index)
Expand Down
4 changes: 4 additions & 0 deletions stdlib/Pkg/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ temp_pkg_dir() do project_path; cd(project_path) do
c, r = test_complete("help r")
@test "remove" in c
@test !("rm" in c)

c, r = test_complete("add REPL")
# Filtered by version
@test !("REPL" in c)
end end

temp_pkg_dir() do project_path; cd(project_path) do
Expand Down

0 comments on commit ec9e5cf

Please sign in to comment.