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

fixes for getindex tab-completion #31499

Merged
merged 2 commits into from
Jun 15, 2019
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
23 changes: 8 additions & 15 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,11 @@ function dict_identifier_key(str,tag)
sym = Symbol(name)
isdefined(obj, sym) || return (nothing, nothing, nothing)
obj = getfield(obj, sym)
# Avoid `isdefined(::Array, ::Symbol)`
isa(obj, Array) && return (nothing, nothing, nothing)
end
begin_of_key = first(something(findnext(r"\S", str, nextind(str, end_of_identifier) + 1), 1)) # 1 for [
begin_of_key==0 && return (true, nothing, nothing)
partial_key = str[begin_of_key:end]
(isa(obj, AbstractDict) && length(obj) < 1e6) || return (true, nothing, nothing)
return (obj, partial_key, begin_of_key)
(isa(obj, AbstractDict) && length(obj) < 1_000_000) || return (nothing, nothing, nothing)
begin_of_key = something(findnext(!isspace, str, nextind(str, end_of_identifier) + 1), # +1 for [
lastindex(str)+1)
return (obj, str[begin_of_key:end], begin_of_key)
end

# This needs to be a separate non-inlined function, see #19441
Expand Down Expand Up @@ -581,13 +578,9 @@ function completions(string, pos, context_module=Main)::Completions
# if completing a key in a Dict
identifier, partial_key, loc = dict_identifier_key(partial,inc_tag)
if identifier !== nothing
if partial_key !== nothing
matches = find_dict_matches(identifier, partial_key)
length(matches)==1 && (length(string) <= pos || string[pos+1] != ']') && (matches[1]*="]")
length(matches)>0 && return [DictCompletion(identifier, match) for match in sort!(matches)], loc:pos, true
else
return Completion[], 0:-1, false
end
matches = find_dict_matches(identifier, partial_key)
length(matches)==1 && (lastindex(string) <= pos || string[nextind(string,pos)] != ']') && (matches[1]*=']')
length(matches)>0 && return [DictCompletion(identifier, match) for match in sort!(matches)], loc:pos, true
end

# otherwise...
Expand All @@ -605,7 +598,7 @@ function completions(string, pos, context_module=Main)::Completions
length(paths) == 1 && # Only close if there's a single choice,
!isdir(expanduser(replace(string[startpos:prevind(string, first(r))] * paths[1].path,
r"\\ " => " "))) && # except if it's a directory
(length(string) <= pos ||
(lastindex(string) <= pos ||
string[nextind(string,pos)] != '"') # or there's already a " at the cursor.
paths[1] = PathCompletion(paths[1].path * "\"")
end
Expand Down
10 changes: 9 additions & 1 deletion stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ let s = "\"C:\\\\ \\alpha"
@test length(c) == 1
end

# test latex symbol completion in getindex expressions (#24705)
let s = "tuple[\\alpha"
c, r, res = test_complete_context(s)
@test c[1] == "α"
@test r == 7:12
@test length(c) == 1
end

let s = "\\a"
c, r, res = test_complete(s)
"\\alpha" in c
Expand Down Expand Up @@ -863,7 +871,7 @@ function test_dict_completion(dict_name)
@test c == Any[":α]"]
s = "$dict_name["
c, r = test_complete(s)
@test !isempty(c)
@test c == sort!(repr.(keys(Main.CompletionFoo.test_dict)))
end
test_dict_completion("CompletionFoo.test_dict")
test_dict_completion("CompletionFoo.test_customdict")
Expand Down