Skip to content
Open
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
6 changes: 0 additions & 6 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,6 @@ function complete_keyword_argument!(suggestions::Vector{Completion},
kwargs_flag == 2 && return false # one of the previous kwargs is invalid

methods = Completion[]
# Limit kwarg completions to cases when function is concretely known; looking up
# matching methods for abstract functions — particularly `Any` or `Function` — can
# take many seconds to run over the thousands of possible methods. Note that
# isabstracttype would return naively return true for common constructor calls
# like Array, but the REPL's introspection here may know their Type{T}.
isconcretetype(funct) || return false
complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, -1, arg_pos == :kwargs)
# TODO: use args_ex instead of Any[Vararg{Any}] and only provide kwarg completion for
# method calls compatible with the current arguments.
Expand Down
50 changes: 48 additions & 2 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2687,8 +2687,54 @@ f54131 = F54131()

s = "f54131.x(kwa"
a, b, c = completions(s, lastindex(s), @__MODULE__, false)
@test_broken REPLCompletions.KeywordArgumentCompletion("kwarg") in a
@test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1
@test REPLCompletions.KeywordArgumentCompletion("kwarg") in a
@test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 100
end

@kwdef struct T59244
asdf = 1
qwer = 2
end
@kwdef struct S59244{T}
asdf::T = 1
qwer::T = 2
end
@testset "kwarg completion of types" begin
s = "T59244(as"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a

s = "T59244(; qw"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)

s = "S59244(as"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a

s = "S59244(; qw"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)

s = "S59244{Int}(as"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a

s = "S59244{Int}(; qw"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)

s = "S59244{Any}(as"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a

s = "S59244{Any}(; qw"
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)
end

# Completion inside string interpolation
Expand Down