diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index a4c12880866db..8bd4e33a9bfd2 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -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. diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index 360a0bb4aa828..a4adb09402b23 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -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