Skip to content

Commit 9cddfda

Browse files
mbaumanvtjnash
andauthored
Remove restrictions on kwarg tab completion (#59692)
Co-authored-by: Jameson Nash <[email protected]>
1 parent b53c7b8 commit 9cddfda

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
@@ -901,12 +901,6 @@ function complete_keyword_argument!(suggestions::Vector{Completion},
901901
kwargs_flag == 2 && return false # one of the previous kwargs is invalid
902902

903903
methods = Completion[]
904-
# Limit kwarg completions to cases when function is concretely known; looking up
905-
# matching methods for abstract functions — particularly `Any` or `Function` — can
906-
# take many seconds to run over the thousands of possible methods. Note that
907-
# isabstracttype would return naively return true for common constructor calls
908-
# like Array, but the REPL's introspection here may know their Type{T}.
909-
isconcretetype(funct) || return false
910904
complete_methods!(methods, funct, Any[Vararg{Any}], kwargs_ex, -1, arg_pos == :kwargs)
911905
# TODO: use args_ex instead of Any[Vararg{Any}] and only provide kwarg completion for
912906
# 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
@@ -2688,8 +2688,54 @@ f54131 = F54131()
26882688

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

26952741
# Completion inside string interpolation

0 commit comments

Comments
 (0)