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

REPLCompletions: Add completions for var"" identifiers #49294

Merged
merged 2 commits into from
Apr 10, 2023
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Apr 8, 2023

Fixes #49280. Mostly just moving code around, but there's one extra place where we're pattern matching var"". I do hope that after the future parser replacement, we can do these things on the in-progress AST rather than textually.

Fixes #49280. Mostly just moving code around, but there's
one extra place where we're pattern matching var"". I do
hope that after the future parser replacement, we can
do these things on the in-progress AST rather than textually.
stdlib/REPL/test/replcompletions.jl Outdated Show resolved Hide resolved
stdlib/REPL/test/replcompletions.jl Outdated Show resolved Hide resolved
@Keno Keno merged commit d0f4327 into master Apr 10, 2023
@Keno Keno deleted the kf/replcompletevar branch April 10, 2023 13:57
Xnartharax pushed a commit to Xnartharax/julia that referenced this pull request Apr 19, 2023
* REPLCompletions: Add completions for var"" identifiers

Fixes JuliaLang#49280. Mostly just moving code around, but there's
one extra place where we're pattern matching var"". I do
hope that after the future parser replacement, we can
do these things on the in-progress AST rather than textually.

* Apply suggestions from code review

---------

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
Keno added a commit that referenced this pull request Apr 27, 2023
The new completion for `var"` fields (#49294) failed
when the `var"` was at the end of the completion query,
e.g. in `WeirdNames().var"`. This is because we have the
following behavior:

```
julia> findprev(==('x'), "x", 1)
1

julia> findprev(==('x'), "x", 2)
```

REPLCompletions attempt to find `.` starting after the `var"`,
which in this case is at the end of the string. Of course,
the index was probably off by one anyway, because
we didn't want to match `var".`, but nevertheless,
I find this behavior surprising (ref also [1]).
For now, fix this by starting the search before the `var"`,
but we may want to revisit the `findprev` behavior also.

[1] https://github.com/JuliaLang/julia/pull/35742/files#r420945975
Keno added a commit that referenced this pull request Apr 28, 2023
The new completion for `var"` fields (#49294) failed
when the `var"` was at the end of the completion query,
e.g. in `WeirdNames().var"`. This is because we have the
following behavior:

```
julia> findprev(==('x'), "x", 1)
1

julia> findprev(==('x'), "x", 2)
```

REPLCompletions attempt to find `.` starting after the `var"`,
which in this case is at the end of the string. Of course,
the index was probably off by one anyway, because
we didn't want to match `var".`, but nevertheless,
I find this behavior surprising (ref also [1]).
For now, fix this by starting the search before the `var"`,
but we may want to revisit the `findprev` behavior also.

[1] https://github.com/JuliaLang/julia/pull/35742/files#r420945975
KristofferC pushed a commit that referenced this pull request Oct 12, 2023
Fix #51194

This PR fixes a regression introduced in
#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
#49294 (comment),
#50817 (comment)
and probably other places), but for now at least this fixes the
regression.
KristofferC pushed a commit that referenced this pull request Oct 12, 2023
Fix #51194

This PR fixes a regression introduced in
#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
#49294 (comment),
#50817 (comment)
and probably other places), but for now at least this fixes the
regression.

(cherry picked from commit e949236)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tab completion doesn't work correctly for var"" symbols
2 participants