Skip to content

Commit c762ca9

Browse files
know when to release the prefix context
1 parent beda632 commit c762ca9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

stdlib/REPL/src/REPLCompletions.jl

+19-1
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,22 @@ function complete_loading_candidates!(suggestions::Vector{Completion}, pkgstarts
11201120
return suggestions
11211121
end
11221122

1123+
# Check whether we should still be limiting completions to the scope of the prefix
1124+
# i.e. `Base.@time myvar` should complete to `Base.@time myvariable` because `myvariable`
1125+
# is a valid expression in the active module, but not Base
1126+
function in_scope_of_prefix(string::String, pos::Int, separatorpos::Int)
1127+
pos <= separatorpos && return true
1128+
after_separator = string[separatorpos+1:pos]
1129+
isempty(after_separator) && return true
1130+
if any(in(non_identifier_chars), after_separator)
1131+
# Non-identifier chars means we're not in the identifier linked to the prefix
1132+
# i.e. the space in `Base.@time x`, or ( in `Base.@time(x`
1133+
return false
1134+
else
1135+
return true
1136+
end
1137+
end
1138+
11231139
function complete_identifiers!(suggestions::Vector{Completion},
11241140
context_module::Module, string::String, name::String,
11251141
pos::Int, separatorpos::Int, startpos::Int;
@@ -1130,7 +1146,9 @@ function complete_identifiers!(suggestions::Vector{Completion},
11301146
complete_keyword!(suggestions, name)
11311147
complete_keyval!(suggestions, name)
11321148
end
1133-
if separatorpos > 1 && (string[separatorpos] == '.' || string[separatorpos] == ':')
1149+
if separatorpos > 1 &&
1150+
((string[separatorpos] == '.' && in_scope_of_prefix(string, pos, separatorpos)) || string[separatorpos] == ':')
1151+
11341152
s = string[1:prevind(string, separatorpos)]
11351153
# First see if the whole string up to `pos` is a valid expression. If so, use it.
11361154
prefix = Meta.parse(s, raise=false, depwarn=false)

stdlib/REPL/test/replcompletions.jl

+16
Original file line numberDiff line numberDiff line change
@@ -2472,3 +2472,19 @@ let (c, r, res) = test_complete_context("global xxx::Number = Base.", Main)
24722472
@test res
24732473
@test "pi" c
24742474
end
2475+
2476+
# release context once past a qualified name
2477+
for s in ("Base.@time TestInternalBinding", "Base.@time Base.@time TestInternalBinding",
2478+
"Base.@time(TestInternalBinding", "@time(Base.@time TestInternalBinding")
2479+
let (c, r, res) = test_complete_context(s; shift=false)
2480+
@test res
2481+
@test "TestInternalBindingOnly" c
2482+
end
2483+
end
2484+
for s in ("Base.@time TestInternalBindingOnly.bind", "Base.@time Base.@time TestInternalBindingOnly.bind",
2485+
"Base.@time(TestInternalBindingOnly.bind", "@time(Base.@time TestInternalBindingOnly.bind")
2486+
let (c, r, res) = test_complete_context(s; shift=false)
2487+
@test res
2488+
@test "binding" c
2489+
end
2490+
end

0 commit comments

Comments
 (0)