Skip to content

Commit 06797f0

Browse files
committed
[REPLCompletions] use less asinine version of listing module imports for completions
The test crashed on my machine, and I noticed the implementation of this function was entirely nonsense. Fortunately, we already had a more correct implementation of this function in the REPL docview code that we could borrow from to fix this. While here, also filter out macros, since those are rather strange looking to see appearing in the results. We could alternatively use `Base.is_valid_identifier`, since the main point here is to print functions that are accessible in the module by identifier. ``` julia> @eval Base.MainInclude export broken julia> broken = 2 2 julia> ?(┌ Error: Error in the keymap │ exception = │ UndefVarError: `broken` not defined in `Base.MainInclude` ```
1 parent a47b58f commit 06797f0

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

stdlib/REPL/src/REPLCompletions.jl

+11-18
Original file line numberDiff line numberDiff line change
@@ -729,24 +729,17 @@ function complete_methods(ex_org::Expr, context_module::Module=Main, shift::Bool
729729
end
730730

731731
MAX_ANY_METHOD_COMPLETIONS::Int = 10
732-
function recursive_explore_names!(seen::IdSet, callee_module::Module, initial_module::Module, exploredmodules::IdSet{Module}=IdSet{Module}())
733-
push!(exploredmodules, callee_module)
734-
for name in names(callee_module; all=true, imported=true)
735-
if !Base.isdeprecated(callee_module, name) && !startswith(string(name), '#') && isdefined(initial_module, name)
736-
func = getfield(callee_module, name)
737-
if !isa(func, Module)
738-
funct = Core.Typeof(func)
739-
push!(seen, funct)
740-
elseif isa(func, Module) && func exploredmodules
741-
recursive_explore_names!(seen, func, initial_module, exploredmodules)
742-
end
743-
end
732+
733+
moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod)
734+
735+
function accessible(mod::Module)
736+
bindings = IdSet{Any}(Core.Typeof(getglobal(mod, s)) for s in names(mod; all=true, imported=true)
737+
if !Base.isdeprecated(mod, s) && !startswith(string(s), '#') && !startswith(string(s), '@') && isdefined(mod, s))
738+
for used in moduleusings(mod)
739+
union!(bindings, (Core.Typeof(getglobal(used, s)) for s in names(used)
740+
if !Base.isdeprecated(used, s) && !startswith(string(s), '@') && isdefined(used, s)))
744741
end
745-
end
746-
function recursive_explore_names(callee_module::Module, initial_module::Module)
747-
seen = IdSet{Any}()
748-
recursive_explore_names!(seen, callee_module, initial_module)
749-
seen
742+
return collect(bindings)
750743
end
751744

752745
function complete_any_methods(ex_org::Expr, callee_module::Module, context_module::Module, moreargs::Bool, shift::Bool)
@@ -764,7 +757,7 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul
764757
# semicolon for the ".?(" syntax
765758
moreargs && push!(args_ex, Vararg{Any})
766759

767-
for seen_name in recursive_explore_names(callee_module, callee_module)
760+
for seen_name in accessible(callee_module)
768761
complete_methods!(out, seen_name, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS, false)
769762
end
770763

0 commit comments

Comments
 (0)