diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index 3120bb1122bff..43b1dd44dc831 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -41,7 +41,9 @@ struct FieldCompletion <: Completion end struct MethodCompletion <: Completion + tt # may be used by an external consumer to infer return type, etc. method::Method + MethodCompletion(@nospecialize(tt), method::Method) = new(tt, method) end struct BslashCompletion <: Completion @@ -515,7 +517,7 @@ function get_type(T, found::Bool, default_any::Bool) end # Method completion on function call expression that look like :(max(1)) -MAX_METHOD_COMPLETIONS = 40 +const MAX_METHOD_COMPLETIONS = Ref(40) function complete_methods(ex_org::Expr, context_module::Module=Main) out = Completion[] funct, found = get_type(ex_org.args[1], context_module)::Tuple{Any,Bool} @@ -523,12 +525,12 @@ function complete_methods(ex_org::Expr, context_module::Module=Main) args_ex, kwargs_ex = complete_methods_args(ex_org.args[2:end], ex_org, context_module, true, true) push!(args_ex, Vararg{Any}) - complete_methods!(out, funct, args_ex, kwargs_ex, MAX_METHOD_COMPLETIONS::Int) + complete_methods!(out, funct, args_ex, kwargs_ex, MAX_METHOD_COMPLETIONS[]) return out end -MAX_ANY_METHOD_COMPLETIONS = 10 +const MAX_ANY_METHOD_COMPLETIONS = Ref(10) function complete_any_methods(ex_org::Expr, callee_module::Module, context_module::Module, moreargs::Bool, shift::Bool) out = Completion[] args_ex, kwargs_ex = try @@ -548,7 +550,7 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul funct = Core.Typeof(func) if !in(funct, seen) push!(seen, funct) - complete_methods!(out, funct, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS::Int) + complete_methods!(out, funct, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS[]) end elseif callee_module === Main && isa(func, Module) callee_module2 = func @@ -559,7 +561,7 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul funct = Core.Typeof(func) if !in(funct, seen) push!(seen, funct) - complete_methods!(out, funct, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS::Int) + complete_methods!(out, funct, args_ex, kwargs_ex, MAX_ANY_METHOD_COMPLETIONS[]) end end end @@ -617,7 +619,7 @@ function complete_methods!(out::Vector{Completion}, @nospecialize(funct), args_e m isa Vector || return for match in m # TODO: if kwargs_ex, filter out methods without kwargs? - push!(out, MethodCompletion(match.method)) + push!(out, MethodCompletion(t_in, match.method)) end end