Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ?(#TAB method search name exploration #52555

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export completions, shell_completions, bslash_completions, completion_text
using Core: CodeInfo, MethodInstance, CodeInstance, Const
const CC = Core.Compiler
using Base.Meta
using Base: propertynames, something
using Base: propertynames, something, IdSet

abstract type Completion end

Expand Down Expand Up @@ -713,6 +713,26 @@ function complete_methods(ex_org::Expr, context_module::Module=Main, shift::Bool
end

MAX_ANY_METHOD_COMPLETIONS::Int = 10
function recursive_explore_names!(seen::IdSet, callee_module::Module, initial_module::Module, exploredmodules::IdSet{Module}=IdSet{Module}())
push!(exploredmodules, callee_module)
for name in names(callee_module; all=true, imported=true)
if !Base.isdeprecated(callee_module, name) && !startswith(string(name), '#') && isdefined(initial_module, name)
func = getfield(callee_module, name)
if !isa(func, Module)
funct = Core.Typeof(func)
push!(seen, funct)
elseif isa(func, Module) && func ∉ exploredmodules
recursive_explore_names!(seen, func, initial_module, exploredmodules)
end
end
end
end
function recursive_explore_names(callee_module::Module, initial_module::Module)
seen = IdSet{Any}()
recursive_explore_names!(seen, callee_module, initial_module)
seen
end

function complete_any_methods(ex_org::Expr, callee_module::Module, context_module::Module, moreargs::Bool, shift::Bool)
out = Completion[]
args_ex, kwargs_ex, kwargs_flag = try
Expand All @@ -728,32 +748,8 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul
# semicolon for the ".?(" syntax
moreargs && push!(args_ex, Vararg{Any})

seen = Base.IdSet()
for name in names(callee_module; all=true)
if !Base.isdeprecated(callee_module, name) && isdefined(callee_module, name) && !startswith(string(name), '#')
func = getfield(callee_module, name)
if !isa(func, Module)
funct = Core.Typeof(func)
if !in(funct, seen)
push!(seen, funct)
complete_methods!(out, funct, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS, false)
end
elseif callee_module === Main && isa(func, Module)
callee_module2 = func
for name in names(callee_module2)
if !Base.isdeprecated(callee_module2, name) && isdefined(callee_module2, name) && !startswith(string(name), '#')
func = getfield(callee_module, name)
if !isa(func, Module)
funct = Core.Typeof(func)
if !in(funct, seen)
push!(seen, funct)
complete_methods!(out, funct, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS, false)
end
end
end
end
end
end
for seen_name in recursive_explore_names(callee_module, callee_module)
complete_methods!(out, seen_name, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS, false)
end

if !shift
Expand Down
7 changes: 7 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ let ex = quote
struct WeirdNames end
Base.propertynames(::WeirdNames) = (Symbol("oh no!"), Symbol("oh yes!"))

# https://github.com/JuliaLang/julia/issues/52551#issuecomment-1858543413
export exported_symbol
exported_symbol(::WeirdNames) = nothing

end # module CompletionFoo
test_repl_comp_dict = CompletionFoo.test_dict
test_repl_comp_customdict = CompletionFoo.test_customdict
Expand Down Expand Up @@ -742,6 +746,9 @@ end

#TODO: @test_nocompletion("CompletionFoo.?(3; len2=5; ")

# https://github.com/JuliaLang/julia/issues/52551
@test !isempty(test_complete("?("))

#################################################################

# Test method completion with varargs
Expand Down