Skip to content

Commit 6aa7114

Browse files
IanButterworthKristofferC
authored andcommitted
fix eagerly stopping hint completions (#4201)
(cherry picked from commit 6f309f1)
1 parent 069a6d7 commit 6aa7114

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ext/REPLExt/completions.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ end
5454

5555

5656
const JULIA_UUID = UUID("1222c4b2-2114-5bfd-aeef-88e4692bbb3e")
57-
function complete_remote_package(partial; hint::Bool)
58-
found_match = false
59-
isempty(partial) && return String[]
57+
function complete_remote_package!(comps, partial; hint::Bool)
58+
isempty(partial) && return true # true means returned early
59+
found_match = !isempty(comps)
6060
cmp = Set{String}()
6161
for reg in Registry.reachable_registries()
6262
for (uuid, regpkg) in reg
@@ -80,9 +80,9 @@ function complete_remote_package(partial; hint::Bool)
8080
if is_julia_compat === nothing || is_julia_compat
8181
push!(cmp, name)
8282
# In hint mode the result is only used if there is a single matching entry
83-
# so we abort the search
83+
# so we can return no matches in case of more than one match
8484
if hint && found_match
85-
return sort!(collect(cmp))
85+
return true # true means returned early
8686
end
8787
found_match = true
8888
break
@@ -91,7 +91,8 @@ function complete_remote_package(partial; hint::Bool)
9191
end
9292
end
9393
end
94-
return sort!(collect(cmp))
94+
append!(comps, sort!(collect(cmp)))
95+
return false # false means performed full search
9596
end
9697

9798
function complete_help(options, partial; hint::Bool)
@@ -149,8 +150,9 @@ function complete_add_dev(options, partial, i1, i2; hint::Bool)
149150
if occursin(Base.Filesystem.path_separator_re, partial)
150151
return comps, idx, !isempty(comps)
151152
end
152-
comps = vcat(comps, sort(complete_remote_package(partial; hint)))
153-
if !isempty(partial)
153+
returned_early = complete_remote_package!(comps, partial; hint)
154+
# returning early means that no further search should be done here
155+
if !returned_early
154156
append!(comps, filter!(startswith(partial), [info.name for info in values(Types.stdlib_infos())]))
155157
end
156158
return comps, idx, !isempty(comps)

0 commit comments

Comments
 (0)