Skip to content

Commit

Permalink
REPLCompletions: only complete kwargs in kwarg position (#51801)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Oct 22, 2023
1 parent fb01dd2 commit fa66820
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,12 @@ function complete_keyword_argument(partial, last_idx, context_module)
end

suggestions = Completion[KeywordArgumentCompletion(kwarg) for kwarg in kwargs]
append!(suggestions, complete_symbol(nothing, last_word, Returns(true), context_module))
append!(suggestions, complete_keyval(last_word))

# Only add these if not in kwarg space. i.e. not in `foo(; `
if kwargs_flag == 0
append!(suggestions, complete_symbol(nothing, last_word, Returns(true), context_module))
append!(suggestions, complete_keyval(last_word))
end

return sort!(suggestions, by=completion_text), wordrange
end
Expand Down
14 changes: 7 additions & 7 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1457,22 +1457,22 @@ end
c, r = test_complete("CompletionFoo.kwtest3(a;foob")
@test c == ["foobar="]
c, r = test_complete("CompletionFoo.kwtest3(a; le")
@test "length" c # provide this kind of completion in case the user wants to splat a variable
@test "length" c
@test "length=" c
@test "len2=" c
@test "len2" c
c, r = test_complete("CompletionFoo.kwtest3.(a;\nlength")
@test "length" c
@test "length" c
@test "length=" c
c, r = test_complete("CompletionFoo.kwtest3(a, length=4, l")
@test "length" c
@test "length=" c # since it was already used, do not suggest it again
@test "len2=" c
c, r = test_complete("CompletionFoo.kwtest3(a; kwargs..., fo")
@test "foreach" c # provide this kind of completion in case the user wants to splat a variable
@test "foreach" c
@test "foobar=" c
c, r = test_complete("CompletionFoo.kwtest3(a; another!kwarg=0, le")
@test "length" c
@test "length" c
@test "length=" c # the first method could be called and `anotherkwarg` slurped
@test "len2=" c
c, r = test_complete("CompletionFoo.kwtest3(a; another!")
Expand All @@ -1486,19 +1486,19 @@ end
c, r = test_complete_foo("kwtest3(blabla; unknown=4, namedar")
@test c == ["namedarg="]
c, r = test_complete_foo("kwtest3(blabla; named")
@test "named" c
@test "named" c
@test "namedarg=" c
@test "len2" c
c, r = test_complete_foo("kwtest3(blabla; named.")
@test c == ["len2"]
c, r = test_complete_foo("kwtest3(blabla; named..., another!")
@test c == ["another!kwarg="]
c, r = test_complete_foo("kwtest3(blabla; named..., len")
@test "length" c
@test "length" c
@test "length=" c
@test "len2=" c
c, r = test_complete_foo("kwtest3(1+3im; named")
@test "named" c
@test "named" c
# TODO: @test "namedarg=" ∉ c
@test "len2" c
c, r = test_complete_foo("kwtest3(1+3im; named.")
Expand Down

0 comments on commit fa66820

Please sign in to comment.