Skip to content

Commit

Permalink
[REPLCompletions] follow up #43865, keep input tuple type in `MethodC…
Browse files Browse the repository at this point in the history
…ompletion`

`MethodCompletion.tt` is being used by an external consumer like Juno or
VSCode's runtime completion features to get additional information like
return type, etc.
  • Loading branch information
aviatesk committed Jan 27, 2022
1 parent 9868411 commit 877000a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -515,20 +517,20 @@ 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}
!found && return out

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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 877000a

Please sign in to comment.