Skip to content

Commit 53c99ed

Browse files
committed
Handle infix operators in REPL completion
1 parent 6a1af76 commit 53c99ed

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,17 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
10141014
ex = Meta.parse(lookup_name, raise=false, depwarn=false)
10151015
end
10161016
isexpr(ex, :incomplete) && (ex = nothing)
1017+
elseif isexpr(ex, :call) && length(ex.args) > 1
1018+
isinfix = s[end] != ')'
1019+
# A complete call expression that does not finish with ')' is an infix call.
1020+
if !isinfix
1021+
# Handle infix call argument completion of the form bar + foo(qux).
1022+
frange, end_of_identifier = find_start_brace(@view s[1:end-1])
1023+
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
1024+
end
1025+
if isinfix
1026+
ex = ex.args[end]
1027+
end
10171028
end
10181029
end
10191030
append!(suggestions, complete_symbol(ex, name, ffunc, context_module))

stdlib/REPL/test/replcompletions.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let ex = quote
2525
(::Test_y)() = "", ""
2626
unicode_αβγ = Test_y(1)
2727

28+
Base.:(+)(x::Test_x, y::Test_y) = Test_x(Test_y(x.xx.yy + y.yy))
2829
module CompletionFoo2
2930

3031
end
@@ -2051,3 +2052,14 @@ end
20512052
# If this last test starts failing, that's okay, just pick a new example symbol:
20522053
@test !Base.isexported(Base, :ispublic)
20532054
end
2055+
2056+
# issue #51194
2057+
for (s, compl) in (("2*CompletionFoo.nam", "named"),
2058+
(":a isa CompletionFoo.test!1", "test!12"),
2059+
("-CompletionFoo.Test_y(3).", "yy"),
2060+
("99 ⨷⁻ᵨ⁷ CompletionFoo.type_test.", "xx"),
2061+
("CompletionFoo.type_test + CompletionFoo.Test_y(2).", "yy"),
2062+
("foo'CompletionFoo.test!1", "test!12"))
2063+
c, r = test_complete(s)
2064+
@test only(c) == compl
2065+
end

0 commit comments

Comments
 (0)