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
  • Loading branch information
IanButterworth authored Oct 21, 2024
1 parent 04259da commit 1c67d0c
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 @@ -480,6 +480,7 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
i = firstindex(r)
braces = in_comment = 0
in_single_quotes = in_double_quotes = in_back_ticks = false
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 @@ -502,7 +503,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 @@ -1197,7 +1200,9 @@ function complete_identifiers!(suggestions::Vector{Completion},
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) == prefix.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) == prefix.args[end]
end
end
if isinfix
prefix = prefix.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 @@ -340,6 +340,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 1c67d0c

Please sign in to comment.