Skip to content

Commit fe891d1

Browse files
IanButterworthKristofferC
authored andcommitted
REPL: fix brace detection when ' is used for transpose (#56252)
(cherry picked from commit 1c67d0c)
1 parent 2454b24 commit fe891d1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
400400
in_double_quotes = false
401401
in_back_ticks = false
402402
in_comment = 0
403+
num_single_quotes_in_string = count('\'', s)
403404
while i <= ncodeunits(r)
404405
c, i = iterate(r, i)
405406
if c == '#' && i <= ncodeunits(r) && iterate(r, i)[1] == '='
@@ -422,7 +423,9 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
422423
braces += 1
423424
elseif c == c_end
424425
braces -= 1
425-
elseif c == '\''
426+
elseif c == '\'' && num_single_quotes_in_string % 2 == 0
427+
# ' can be a transpose too, so check if there are even number of 's in the string
428+
# TODO: This probably needs to be more robust
426429
in_single_quotes = true
427430
elseif c == '"'
428431
in_double_quotes = true
@@ -1079,7 +1082,9 @@ function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ff
10791082
if !isinfix
10801083
# Handle infix call argument completion of the form bar + foo(qux).
10811084
frange, end_of_identifier = find_start_brace(@view s[1:prevind(s, end)])
1082-
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
1085+
if !isempty(frange) # if find_start_brace fails to find the brace just continue
1086+
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == ex.args[end]
1087+
end
10831088
end
10841089
if isinfix
10851090
ex = ex.args[end]

stdlib/REPL/test/replcompletions.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ end
325325
# inexistent completion inside a cmd
326326
@test_nocompletion("run(`lol")
327327

328+
# issue 55856: copy(A').<TAB> errors in the REPL
329+
let
330+
c, r = test_complete("copy(A').")
331+
@test isempty(c)
332+
end
333+
328334
# test latex symbol completions
329335
let s = "\\alpha"
330336
c, r = test_bslashcomplete(s)

0 commit comments

Comments
 (0)