Skip to content

Commit 1c67d0c

Browse files
REPL: fix brace detection when ' is used for transpose (#56252)
1 parent 04259da commit 1c67d0c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stdlib/REPL/src/REPLCompletions.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
480480
i = firstindex(r)
481481
braces = in_comment = 0
482482
in_single_quotes = in_double_quotes = in_back_ticks = false
483+
num_single_quotes_in_string = count('\'', s)
483484
while i <= ncodeunits(r)
484485
c, i = iterate(r, i)
485486
if c == '#' && i <= ncodeunits(r) && iterate(r, i)[1] == '='
@@ -502,7 +503,9 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
502503
braces += 1
503504
elseif c == c_end
504505
braces -= 1
505-
elseif c == '\''
506+
elseif c == '\'' && num_single_quotes_in_string % 2 == 0
507+
# ' can be a transpose too, so check if there are even number of 's in the string
508+
# TODO: This probably needs to be more robust
506509
in_single_quotes = true
507510
elseif c == '"'
508511
in_double_quotes = true
@@ -1197,7 +1200,9 @@ function complete_identifiers!(suggestions::Vector{Completion},
11971200
if !isinfix
11981201
# Handle infix call argument completion of the form bar + foo(qux).
11991202
frange, end_of_identifier = find_start_brace(@view s[1:prevind(s, end)])
1200-
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == prefix.args[end]
1203+
if !isempty(frange) # if find_start_brace fails to find the brace just continue
1204+
isinfix = Meta.parse(@view(s[frange[1]:end]), raise=false, depwarn=false) == prefix.args[end]
1205+
end
12011206
end
12021207
if isinfix
12031208
prefix = prefix.args[end]

stdlib/REPL/test/replcompletions.jl

+6
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ end
340340
# inexistent completion inside a cmd
341341
@test_nocompletion("run(`lol")
342342

343+
# issue 55856: copy(A').<TAB> errors in the REPL
344+
let
345+
c, r = test_complete("copy(A').")
346+
@test isempty(c)
347+
end
348+
343349
# test latex symbol completions
344350
let s = "\\alpha"
345351
c, r = test_bslashcomplete(s)

0 commit comments

Comments
 (0)