@@ -1120,6 +1120,22 @@ function complete_loading_candidates!(suggestions::Vector{Completion}, pkgstarts
1120
1120
return suggestions
1121
1121
end
1122
1122
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
+
1123
1139
function complete_identifiers! (suggestions:: Vector{Completion} ,
1124
1140
context_module:: Module , string:: String , name:: String ,
1125
1141
pos:: Int , separatorpos:: Int , startpos:: Int ;
@@ -1130,7 +1146,9 @@ function complete_identifiers!(suggestions::Vector{Completion},
1130
1146
complete_keyword! (suggestions, name)
1131
1147
complete_keyval! (suggestions, name)
1132
1148
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
+
1134
1152
s = string[1 : prevind (string, separatorpos)]
1135
1153
# First see if the whole string up to `pos` is a valid expression. If so, use it.
1136
1154
prefix = Meta. parse (s, raise= false , depwarn= false )
0 commit comments