Skip to content

Commit 163391c

Browse files
committed
Handle infix operators in REPL completion
1 parent 26ceebf commit 163391c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
966966
append!(suggestions, complete_keyval(name))
967967
end
968968
if dotpos > 1 && string[dotpos] == '.'
969-
s = string[1:dotpos-1]
969+
s = string[1:prevind(string, dotpos)]
970970
# First see if the whole string up to `pos` is a valid expression. If so, use it.
971971
ex = Meta.parse(s, raise=false, depwarn=false)
972972
if isexpr(ex, :incomplete)
@@ -1005,6 +1005,17 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
10051005
ex = Meta.parse(lookup_name, raise=false, depwarn=false)
10061006
end
10071007
isexpr(ex, :incomplete) && (ex = nothing)
1008+
elseif isexpr(ex, :call) && length(ex.args) > 1
1009+
isinfix = s[end] != ')'
1010+
# A complete call expression that does not finish with ')' is an infix call.
1011+
if !isinfix
1012+
# Handle infix call argument completion of the form bar + foo(qux).
1013+
frange, end_of_identifier = find_start_brace(@view s[1:end-1])
1014+
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
1015+
end
1016+
if isinfix
1017+
ex = ex.args[end]
1018+
end
10081019
end
10091020
end
10101021
append!(suggestions, complete_symbol(ex, name, ffunc, context_module))

stdlib/REPL/test/replcompletions.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ let ex = quote
2323
end
2424
type_test = Test_x(Test_y(1))
2525
(::Test_y)() = "", ""
26+
Base.:(+)(x::Test_x, y::Test_y) = Test_x(Test_y(x.xx.yy + y.yy))
2627
module CompletionFoo2
2728

2829
end
@@ -1910,3 +1911,16 @@ end
19101911
# If this last test starts failing, that's okay, just pick a new example symbol:
19111912
@test !Base.isexported(Base, :ispublic)
19121913
end
1914+
1915+
# issue #51194
1916+
for (s, compl) in (("2*CompletionFoo.nam", "named"),
1917+
(":a isa CompletionFoo.test!1", "test!12"),
1918+
("-CompletionFoo.Test_y(3).", "yy"),
1919+
("99 ⨷⁻ᵨ⁷ CompletionFoo.type_test.", "xx"),
1920+
("CompletionFoo.type_test + CompletionFoo.Test_y(2).", "yy"),
1921+
("foo'CompletionFoo.test!1", "test!12"))
1922+
c, r = test_complete(s)
1923+
@test only(c) == compl
1924+
end
1925+
1926+
@test isempty(first(test_complete("ℯ.")))

0 commit comments

Comments
 (0)