From da0b845ec70c43e86c2fb7f7ceaf946bdb90952d Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Mon, 29 Sep 2025 14:38:07 -0400 Subject: [PATCH 1/3] Remove restrictions on tab completion Resolves issue #59244 on master --- stdlib/REPL/src/REPLCompletions.jl | 3 +- stdlib/REPL/test/replcompletions.jl | 48 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index a4c12880866db..c75354cbe8a84 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -905,8 +905,7 @@ function complete_keyword_argument!(suggestions::Vector{Completion}, # 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 + # like Array, but the REPL's introspection here may infer a Type{T} that we need to unwrap. 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..eb636fcaf7414 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -2687,10 +2687,56 @@ f54131 = F54131() s = "f54131.x(kwa" a, b, c = completions(s, lastindex(s), @__MODULE__, false) - @test_broken REPLCompletions.KeywordArgumentCompletion("kwarg") in a + @test REPLCompletions.KeywordArgumentCompletion("kwarg") in a @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1 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 let s = "\"example: \$varflo" c, r = test_complete_foo(s) From 5e1722abdbec9af206afb24239147f25cd89ee95 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Mon, 29 Sep 2025 14:39:10 -0400 Subject: [PATCH 2/3] also remove outdated comment --- stdlib/REPL/src/REPLCompletions.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index c75354cbe8a84..8bd4e33a9bfd2 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -901,11 +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 infer a Type{T} that we need to unwrap. 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. From e7dd1451efdf3edfdc38bd0794e6cefa012ec518 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Wed, 1 Oct 2025 09:32:37 -0400 Subject: [PATCH 3/3] Update stdlib/REPL/test/replcompletions.jl Co-authored-by: Jameson Nash --- stdlib/REPL/test/replcompletions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index eb636fcaf7414..a4adb09402b23 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -2688,7 +2688,7 @@ f54131 = F54131() s = "f54131.x(kwa" a, b, c = completions(s, lastindex(s), @__MODULE__, false) @test REPLCompletions.KeywordArgumentCompletion("kwarg") in a - @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1 + @test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 100 end @kwdef struct T59244