Skip to content

Commit 0be5439

Browse files
mbaumanvtjnash
authored andcommitted
Remove restrictions on kwarg tab completion (#59692)
Co-authored-by: Jameson Nash <[email protected]> (cherry picked from commit 9cddfda)
1 parent 4f05d8d commit 0be5439

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,12 +905,6 @@ function complete_keyword_argument!(suggestions::Vector{Completion},
905905
kwargs_flag == 2 && return false # one of the previous kwargs is invalid
906906

907907
methods = Completion[]
908-
# Limit kwarg completions to cases when function is concretely known; looking up
909-
# matching methods for abstract functions — particularly `Any` or `Function` — can
910-
# take many seconds to run over the thousands of possible methods. Note that
911-
# isabstracttype would return naively return true for common constructor calls
912-
# like Array, but the REPL's introspection here may know their Type{T}.
913-
isconcretetype(funct) || return false
914908
complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, -1, arg_pos == :kwargs)
915909
# TODO: use args_ex instead of Any[Vararg{Any}] and only provide kwarg completion for
916910
# method calls compatible with the current arguments.

stdlib/REPL/test/replcompletions.jl

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,8 +2687,54 @@ f54131 = F54131()
26872687

26882688
s = "f54131.x(kwa"
26892689
a, b, c = completions(s, lastindex(s), @__MODULE__, false)
2690-
@test_broken REPLCompletions.KeywordArgumentCompletion("kwarg") in a
2691-
@test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1
2690+
@test REPLCompletions.KeywordArgumentCompletion("kwarg") in a
2691+
@test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 100
2692+
end
2693+
2694+
@kwdef struct T59244
2695+
asdf = 1
2696+
qwer = 2
2697+
end
2698+
@kwdef struct S59244{T}
2699+
asdf::T = 1
2700+
qwer::T = 2
2701+
end
2702+
@testset "kwarg completion of types" begin
2703+
s = "T59244(as"
2704+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2705+
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a
2706+
2707+
s = "T59244(; qw"
2708+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2709+
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
2710+
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)
2711+
2712+
s = "S59244(as"
2713+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2714+
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a
2715+
2716+
s = "S59244(; qw"
2717+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2718+
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
2719+
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)
2720+
2721+
s = "S59244{Int}(as"
2722+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2723+
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a
2724+
2725+
s = "S59244{Int}(; qw"
2726+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2727+
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
2728+
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)
2729+
2730+
s = "S59244{Any}(as"
2731+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2732+
@test REPLCompletions.KeywordArgumentCompletion("asdf") in a
2733+
2734+
s = "S59244{Any}(; qw"
2735+
a, b, c = completions(s, lastindex(s), @__MODULE__, #= shift =# false)
2736+
@test REPLCompletions.KeywordArgumentCompletion("qwer") in a
2737+
@test REPLCompletions.KeywordArgumentCompletion("qwer") == only(a)
26922738
end
26932739

26942740
# Completion inside string interpolation

0 commit comments

Comments
 (0)