Skip to content

Commit 028d292

Browse files
committed
Fix starting range in REPLCompletions
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
1 parent f11bfc6 commit 028d292

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ function completions(string::String, pos::Int, context_module::Module=Main, shif
10211021
ok, ret = bslash_completions(string, pos)
10221022
ok && return ret
10231023
startpos = first(varrange) + 4
1024-
dotpos = something(findprev(isequal('.'), string, startpos), 0)
1024+
dotpos = something(findprev(isequal('.'), string, first(varrange)-1), 0)
10251025
return complete_identifiers!(Completion[], ffunc, context_module, string,
10261026
string[startpos:pos], pos, dotpos, startpos)
10271027
# otherwise...

stdlib/REPL/test/replcompletions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ let s = "var\"complicated "
18191819
@test c == Any["var\"complicated symbol with spaces\""]
18201820
end
18211821

1822-
let s = "WeirdNames().var\"oh "
1822+
for s in ("WeirdNames().var\"oh ", "WeirdNames().var\"")
18231823
c, r = test_complete_foo(s)
18241824
@test c == Any["var\"oh no!\"", "var\"oh yes!\""]
18251825
end

0 commit comments

Comments
 (0)