Handle infix operators in REPL completion (#51366)
Fix https://github.com/JuliaLang/julia/issues/51194
This PR fixes a regression introduced in
https://github.com/JuliaLang/julia/pull/49294, so I believe it should be
backported to v1.10.
In the current code, completion of `qux(foo, bar.` is detected by
parsing `foo(qux, bar` as an incomplete expression, and then looking for
the sub-expression to complete (here, `bar.`). This approach fails
however for infix calls, since completing `foo + bar.` starts by parsing
`foo + bar`, which is a complete call expression, and so the code
behaves as if completing `(foo + bar).` instead of `bar.`. This leads to
the current problematic behaviour:
```julia
julia> Complex(1, 3) + (4//5).#TAB
im
re
```
which would be correct for `(Complex(1, 3) + (4//5)).#TAB`, but here we
expect
```julia
julia> Complex(1, 3) + (4//5).#TAB
den
num
```
This PR fixes that by trying to detect infix calls. In the long term,
all this ad-hoc and probably somewhat wrong string processing should be
replaced by proper use of `JuliaSyntax` (as mentioned in
https://github.com/JuliaLang/julia/pull/49294#issue-1659443492,
https://github.com/JuliaLang/julia/issues/50817#issuecomment-1668773346
and probably other places), but for now at least this fixes the
regression.