Skip to content

Commit a49d479

Browse files
author
KristofferC
committed
fixup
1 parent 5104543 commit a49d479

File tree

7 files changed

+31
-26
lines changed

7 files changed

+31
-26
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ version = "1.11.0"
99
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
1010
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1111
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
12-
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
1312
FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
1413
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
1514
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
@@ -39,4 +38,4 @@ Preferences = "21216c6a-2e73-6563-6e65-726566657250"
3938
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4039

4140
[targets]
42-
test = ["Test", "Preferences", "HistoricalStdlibVersions"]
41+
test = ["REPL", "Test", "Preferences", "HistoricalStdlibVersions"]

ext/REPLExt/REPLExt.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import REPL
66
import .REPL: LineEdit, REPLCompletions, TerminalMenus
77

88
import Pkg
9-
import .Pkg: linewrap, pathrepr, compat, can_fancyprint, printpkgstyle
9+
import .Pkg: linewrap, pathrepr, compat, can_fancyprint, printpkgstyle, PKGMODE_PROJECT
1010
using .Pkg: Types, Operations, API, Registry, Resolve, REPLMode
1111

12-
using .REPLMode: Statement, CommandSpec, Command, prepare_cmd
12+
using .REPLMode: Statement, CommandSpec, Command, prepare_cmd, tokenize, core_parse, SPECS, api_options, parse_option, api_options, is_opt, wrap_option
1313

1414
using .Types: Context, PkgError, pkgerror, EnvCache
1515

@@ -177,6 +177,7 @@ function repl_init(repl::REPL.AbstractREPL)
177177
return
178178
end
179179

180+
const REG_WARNED = Ref{Bool}(false)
180181

181182
function try_prompt_pkg_add(pkgs::Vector{Symbol})
182183
ctx = try
@@ -216,12 +217,12 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
216217
printstyled(ctx.io, ""; color=:green)
217218
println(ctx.io, "Install package$(plural4)?")
218219
msg2 = string("add ", join(available_pkgs, ' '))
219-
for (i, line) in pairs(linewrap(msg2; io = ctx.io, padding = length(string(" | ", REPLMode.promptf()))))
220+
for (i, line) in pairs(linewrap(msg2; io = ctx.io, padding = length(string(" | ", promptf()))))
220221
printstyled(ctx.io, ""; color=:green)
221222
if i == 1
222-
printstyled(ctx.io, REPLMode.promptf(); color=:blue)
223+
printstyled(ctx.io, promptf(); color=:blue)
223224
else
224-
print(ctx.io, " "^length(REPLMode.promptf()))
225+
print(ctx.io, " "^length(promptf()))
225226
end
226227
println(ctx.io, line)
227228
end

ext/REPLExt/completions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function complete_argument(spec::CommandSpec, options::Vector{String},
187187
e isa PkgError && return String[]
188188
rethrow()
189189
end
190-
return applicable(spec.completions, opts, partial, offset, index)
190+
return spec.completions(opts, partial, offset, index)
191191
end
192192

193193
function _completions(input, final, offset, index)

src/REPLMode/REPLMode.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,5 @@ Some commands have an alias, indicated below.
497497
end
498498

499499
const help = gen_help()
500-
const REG_WARNED = Ref{Bool}(false)
501500

502501
end #module

src/Registry/Registry.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function download_registries(io::IO, regs::Vector{RegistrySpec}, depot::String=d
211211
printpkgstyle(io, :Symlinked, "registry `$(Base.contractuser(registry.name))` to `$(Base.contractuser(regpath))`")
212212
return
213213
elseif reg.url !== nothing && reg.linked == true
214-
pkgerror("""
214+
Pkg.Types.pkgerror("""
215215
A symlinked registry was requested but `path` was not set and `url` was set to `$url`.
216216
Set only `path` and `linked = true` to use registry symlinking.
217217
""")
@@ -382,7 +382,7 @@ function update(regs::Vector{RegistrySpec} = RegistrySpec[]; io::IO=stderr_f(),
382382
for reg in unique(r -> r.uuid, find_installed_registries(io, depot_regs; depots=[depot]); seen=Set{UUID}())
383383
prev_update = get(registry_update_log, string(reg.uuid), nothing)::Union{Nothing, DateTime}
384384
if prev_update !== nothing
385-
diff = now() - prev_update
385+
diff = now() - prev_update
386386
if diff < update_cooldown
387387
@debug "Skipping updating registry $(reg.name) since it is on cooldown: $(Dates.canonicalize(Millisecond(update_cooldown) - diff)) left"
388388
continue

src/Types.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ function ensure_resolved(ctx::Context, manifest::Manifest,
10091009
join(io, what, ", ", " or ")
10101010
print(io, ")")
10111011
all_names = available_names(ctx; manifest, include_registries = registry)
1012-
all_names_ranked, any_score_gt_zero = FuzzySort.fuzzysort(name, all_names)
1012+
all_names_ranked, any_score_gt_zero = fuzzysort(name, all_names)
10131013
if any_score_gt_zero
10141014
println(io)
10151015
prefix = " Suggestions:"
@@ -1032,7 +1032,11 @@ function ensure_resolved(ctx::Context, manifest::Manifest,
10321032
pkgerror(msg)
10331033
end
10341034

1035-
1035+
# copied from REPL to efficiently expose if any score is >0
1036+
function fuzzysort(search::String, candidates::Vector{String})
1037+
scores = map(cand -> (FuzzySorting.fuzzyscore(search, cand), -Float64(FuzzySorting.levenshtein(search, cand))), candidates)
1038+
candidates[sortperm(scores)] |> reverse, any(s -> s[1] > 0, scores)
1039+
end
10361040

10371041
function available_names(ctx::Context = Context(); manifest::Manifest = ctx.env.manifest, include_registries::Bool = true)
10381042
all_names = String[]

test/repl.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ using UUIDs
1010
using Test
1111
using TOML
1212
import LibGit2
13+
import REPL
14+
const REPLExt = Base.get_extension(Pkg, :REPLExt)
1315

1416
using ..Utils
1517

@@ -288,7 +290,7 @@ temp_pkg_dir() do depot
288290
end
289291
end
290292

291-
test_complete(s) = Pkg.REPLMode.completions(s, lastindex(s))
293+
test_complete(s) = REPLExt.completions(s, lastindex(s))
292294
apply_completion(str) = begin
293295
c, r, s = test_complete(str)
294296
str[1:prevind(str, first(r))]*first(c)
@@ -596,32 +598,32 @@ end
596598
end
597599

598600
with_temp_env("SomeEnv") do
599-
@test Pkg.REPLMode.promptf() == "(SomeEnv) pkg> "
601+
@test REPLExt.promptf() == "(SomeEnv) pkg> "
600602
end
601603

602604
with_temp_env("this_is_a_test_for_truncating_long_folder_names_in_the_prompt") do
603-
@test Pkg.REPLMode.promptf() == "(this_is_a_test_for_truncati...) pkg> "
605+
@test REPLExt.promptf() == "(this_is_a_test_for_truncati...) pkg> "
604606
end
605607

606608
env_name = "Test2"
607609
with_temp_env(env_name) do env_path
608610
projfile_path = joinpath(env_path, "Project.toml")
609-
@test Pkg.REPLMode.promptf() == "($env_name) pkg> "
611+
@test REPLExt.promptf() == "($env_name) pkg> "
610612

611613
newname = "NewName"
612614
set_name(projfile_path, newname)
613-
@test Pkg.REPLMode.promptf() == "($newname) pkg> "
615+
@test REPLExt.promptf() == "($newname) pkg> "
614616
cd(env_path) do
615-
@test Pkg.REPLMode.promptf() == "($newname) pkg> "
617+
@test REPLExt.promptf() == "($newname) pkg> "
616618
end
617-
@test Pkg.REPLMode.promptf() == "($newname) pkg> "
619+
@test REPLExt.promptf() == "($newname) pkg> "
618620

619621
newname = "NewNameII"
620622
set_name(projfile_path, newname)
621623
cd(env_path) do
622-
@test Pkg.REPLMode.promptf() == "($newname) pkg> "
624+
@test REPLExt.promptf() == "($newname) pkg> "
623625
end
624-
@test Pkg.REPLMode.promptf() == "($newname) pkg> "
626+
@test REPLExt.promptf() == "($newname) pkg> "
625627
end
626628
end
627629

@@ -711,16 +713,16 @@ end
711713

712714
@testset "REPL missing package install hook" begin
713715
isolate(loaded_depot=true) do
714-
@test Pkg.REPLMode.try_prompt_pkg_add(Symbol[:notapackage]) == false
716+
@test REPLExt.try_prompt_pkg_add(Symbol[:notapackage]) == false
715717

716718
# don't offer to install the dummy "julia" entry that's in General
717-
@test Pkg.REPLMode.try_prompt_pkg_add(Symbol[:julia]) == false
719+
@test REPLExt.try_prompt_pkg_add(Symbol[:julia]) == false
718720

719721
withreply("n") do
720-
@test Pkg.REPLMode.try_prompt_pkg_add(Symbol[:Example]) == false
722+
@test REPLExt.try_prompt_pkg_add(Symbol[:Example]) == false
721723
end
722724
withreply("y") do
723-
@test Pkg.REPLMode.try_prompt_pkg_add(Symbol[:Example]) == true
725+
@test REPLExt.try_prompt_pkg_add(Symbol[:Example]) == true
724726
end
725727
end
726728
end

0 commit comments

Comments
 (0)