Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: fix brace detection when ' is used for transpose #56252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading