Skip to content

Commit a0346ae

Browse files
committed
make DictCompletion context module aware
1 parent 7f28d91 commit a0346ae

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function bslash_completions(string, pos)::Tuple{Bool, Completions}
518518
return (false, (Completion[], 0:-1, false))
519519
end
520520

521-
function dict_identifier_key(str,tag)
521+
function dict_identifier_key(str, tag, context_module = Main)
522522
if tag === :string
523523
str_close = str*"\""
524524
elseif tag === :cmd
@@ -529,7 +529,7 @@ function dict_identifier_key(str,tag)
529529

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

583583
# if completing a key in a Dict
584-
identifier, partial_key, loc = dict_identifier_key(partial,inc_tag)
584+
identifier, partial_key, loc = dict_identifier_key(partial, inc_tag, context_module)
585585
if identifier !== nothing
586586
matches = find_dict_matches(identifier, partial_key)
587587
length(matches)==1 && (lastindex(string) <= pos || string[nextind(string,pos)] != ']') && (matches[1]*=']')

stdlib/REPL/test/replcompletions.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,3 +1061,8 @@ let s = "typeof(+)."
10611061
c, r = test_complete_context(s)
10621062
@test length(c) == length(fieldnames(DataType))
10631063
end
1064+
1065+
let s = "test_dict[\"ab"
1066+
c, r = test_complete_context(s)
1067+
@test c == Any["\"abc\"", "\"abcd\""]
1068+
end

0 commit comments

Comments
 (0)