Skip to content

Commit

Permalink
REPL: fix brace detection when ' is used for transpose (#56252)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1c67d0c)
  • Loading branch information
IanButterworth authored and KristofferC committed Oct 30, 2024
1 parent 2454b24 commit fe891d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
in_double_quotes = false
in_back_ticks = false
in_comment = 0
num_single_quotes_in_string = count('\'', s)
while i <= ncodeunits(r)
c, i = iterate(r, i)
if c == '#' && i <= ncodeunits(r) && iterate(r, i)[1] == '='
Expand All @@ -422,7 +423,9 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
braces += 1
elseif c == c_end
braces -= 1
elseif c == '\''
elseif c == '\'' && num_single_quotes_in_string % 2 == 0
# ' can be a transpose too, so check if there are even number of 's in the string
# TODO: This probably needs to be more robust
in_single_quotes = true
elseif c == '"'
in_double_quotes = true
Expand Down Expand Up @@ -1079,7 +1082,9 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
if !isinfix
# Handle infix call argument completion of the form bar + foo(qux).
frange, end_of_identifier = find_start_brace(@view s[1:prevind(s, end)])
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
if !isempty(frange) # if find_start_brace fails to find the brace just continue
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
end
end
if isinfix
ex = ex.args[end]
Expand Down
6 changes: 6 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ end
# inexistent completion inside a cmd
@test_nocompletion("run(`lol")

# issue 55856: copy(A').<TAB> errors in the REPL
let
c, r = test_complete("copy(A').")
@test isempty(c)
end

# test latex symbol completions
let s = "\\alpha"
c, r = test_bslashcomplete(s)
Expand Down

0 comments on commit fe891d1

Please sign in to comment.