Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle infix operators in REPL completion #51366

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,17 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
ex = Meta.parse(lookup_name, raise=false, depwarn=false)
end
isexpr(ex, :incomplete) && (ex = nothing)
elseif isexpr(ex, :call) && length(ex.args) > 1
isinfix = s[end] != ')'
# A complete call expression that does not finish with ')' is an infix call.
if !isinfix
# Handle infix call argument completion of the form bar + foo(qux).
frange, end_of_identifier = find_start_brace(@view s[1:end-1])
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
end
if isinfix
ex = ex.args[end]
end
end
end
append!(suggestions, complete_symbol(ex, name, ffunc, context_module))
Expand Down
12 changes: 12 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let ex = quote
(::Test_y)() = "", ""
unicode_αβγ = Test_y(1)

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

end
Expand Down Expand Up @@ -2051,3 +2052,14 @@ end
# If this last test starts failing, that's okay, just pick a new example symbol:
@test !Base.isexported(Base, :ispublic)
end

# issue #51194
for (s, compl) in (("2*CompletionFoo.nam", "named"),
(":a isa CompletionFoo.test!1", "test!12"),
("-CompletionFoo.Test_y(3).", "yy"),
("99 ⨷⁻ᵨ⁷ CompletionFoo.type_test.", "xx"),
("CompletionFoo.type_test + CompletionFoo.Test_y(2).", "yy"),
("foo'CompletionFoo.test!1", "test!12"))
c, r = test_complete(s)
@test only(c) == compl
end