Skip to content

Commit

Permalink
make DictCompletion context module aware (#34908)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored and staticfloat committed Apr 21, 2020
1 parent acb7fc3 commit 046bad9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ function bslash_completions(string, pos)::Tuple{Bool, Completions}
return (false, (Completion[], 0:-1, false))
end

function dict_identifier_key(str,tag)
function dict_identifier_key(str, tag, context_module = Main)
if tag === :string
str_close = str*"\""
elseif tag === :cmd
Expand All @@ -529,7 +529,7 @@ function dict_identifier_key(str,tag)

frange, end_of_identifier = find_start_brace(str_close, c_start='[', c_end=']')
isempty(frange) && return (nothing, nothing, nothing)
obj = Main
obj = context_module
for name in split(str[frange[1]:end_of_identifier], '.')
Base.isidentifier(name) || return (nothing, nothing, nothing)
sym = Symbol(name)
Expand Down Expand Up @@ -581,7 +581,7 @@ function completions(string, pos, context_module=Main)::Completions
inc_tag = Base.incomplete_tag(Meta.parse(partial, raise=false, depwarn=false))

# if completing a key in a Dict
identifier, partial_key, loc = dict_identifier_key(partial,inc_tag)
identifier, partial_key, loc = dict_identifier_key(partial, inc_tag, context_module)
if identifier !== nothing
matches = find_dict_matches(identifier, partial_key)
length(matches)==1 && (lastindex(string) <= pos || string[nextind(string,pos)] != ']') && (matches[1]*=']')
Expand Down
5 changes: 5 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1061,3 +1061,8 @@ let s = "typeof(+)."
c, r = test_complete_context(s)
@test length(c) == length(fieldnames(DataType))
end

let s = "test_dict[\"ab"
c, r = test_complete_context(s)
@test c == Any["\"abc\"", "\"abcd\""]
end

0 comments on commit 046bad9

Please sign in to comment.