Skip to content

Commit

Permalink
Fix string index error in tab completion code, fixes #51540 (#51541)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6ce15fc)
  • Loading branch information
jakobnissen authored and KristofferC committed Oct 3, 2023
1 parent 4dc08dc commit 0e9addd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
ex = nothing
comp_keywords && append!(suggestions, complete_keyword(name))
if dotpos > 1 && string[dotpos] == '.'
s = string[1:dotpos-1]
s = string[1:prevind(string, dotpos)]
# First see if the whole string up to `pos` is a valid expression. If so, use it.
ex = Meta.parse(s, raise=false, depwarn=false)
if isexpr(ex, :incomplete)
Expand Down
7 changes: 7 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let ex = quote
end
type_test = Test_x(Test_y(1))
(::Test_y)() = "", ""
unicode_αβγ = Test_y(1)

module CompletionFoo2

end
Expand Down Expand Up @@ -253,6 +255,11 @@ let s = "Main.CompletionFoo.type_test.x"
@test s[r] == "x"
end

let s = "Main.CompletionFoo.unicode_αβγ.y"
c, r = test_complete(s)
@test "yy" in c
end

let s = "Main.CompletionFoo.bar.no_val_available"
c, r = test_complete(s)
@test length(c)==0
Expand Down

0 comments on commit 0e9addd

Please sign in to comment.