Skip to content

Commit

Permalink
Factored representation for REPLCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Liozou committed Mar 4, 2022
1 parent 7bbfe0b commit 3349e87
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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)
method::Base.FactoredMethod
MethodCompletion(@nospecialize(tt), method::Base.FactoredMethod) = new(tt, method)
end

struct BslashCompletion <: Completion
Expand Down Expand Up @@ -78,7 +78,7 @@ function Base.getproperty(c::Completion, name::Symbol)
elseif name === :field
return getfield(c, :field)::Symbol
elseif name === :method
return getfield(c, :method)::Method
return getfield(c, :method)::Base.FactoredMethod
elseif name === :bslash
return getfield(c, :bslash)::String
elseif name === :text
Expand Down Expand Up @@ -575,7 +575,7 @@ function complete_any_methods(ex_org::Expr, callee_module::Module, context_modul
filter!(out) do c
isa(c, TextCompletion) && return false
isa(c, MethodCompletion) || return true
sig = Base.unwrap_unionall(c.method.sig)::DataType
sig = Base.unwrap_unionall(c.method.m.sig)::DataType
return !all(T -> T === Any || T === Vararg{Any}, sig.parameters[2:end])
end
end
Expand Down Expand Up @@ -611,15 +611,24 @@ end
function complete_methods!(out::Vector{Completion}, @nospecialize(funct), args_ex::Vector{Any}, kwargs_ex::Bool, max_method_completions::Int)
# Input types and number of arguments
t_in = Tuple{funct, args_ex...}
m = Base._methods_by_ftype(t_in, nothing, max_method_completions, Base.get_world_counter(),
ml = Base._methods_by_ftype(t_in, nothing, max_method_completions, Base.get_world_counter(),
#=ambig=# true, Ref(typemin(UInt)), Ref(typemax(UInt)), Ptr{Int32}(C_NULL))
if m === false
if ml === false
push!(out, TextCompletion(sprint(Base.show_signature_function, funct) * "( too many methods to show )"))
end
m isa Vector || return
for match in m
ml isa Vector || return
isempty(ml) && return
mm = [m::Core.MethodMatch for m in ml]
first_m = mm[1].method
if first_m.sig === Tuple # Builtin
push!(out, MethodCompletion(t_in, Base.FactoredMethod(first_m)))
return
end
mt = Base.get_methodtable(first_m)
fml = Base.FactoredMethodList(Base.MethodList([m.method for m in mm], mt))
for (fm, pos) in zip(fml.list, fml.positions)
# TODO: if kwargs_ex, filter out methods without kwargs?
push!(out, MethodCompletion(match.spec_types, match.method))
push!(out, MethodCompletion(mm[last(pos)].spec_types, fm))
end
end

Expand Down

0 comments on commit 3349e87

Please sign in to comment.