Skip to content

Commit

Permalink
Method completion with keywords.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoegh committed May 30, 2016
1 parent e4cabab commit 7e48c5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,15 @@ function complete_methods(ex_org::Expr)
out = String[]
t_in = Tuple{Core.Typeof(func), args_ex...} # Input types
na = length(args_ex)+1
for method in methods(func)
ml = methods(func)
kwtype = isdefined(ml.mt, :kwsorter) ? Nullable{DataType}(typeof(ml.mt.kwsorter)) : Nullable{DataType}()
io = IOBuffer()
for method in ml
# Check if the method's type signature intersects the input types
typeintersect(Tuple{method.sig.parameters[1 : min(na, end)]...}, t_in) != Union{} &&
push!(out,string(method))
if typeintersect(Tuple{method.sig.parameters[1 : min(na, end)]...}, t_in) != Union{}
show(io, method, kwtype=kwtype)
push!(out, takebuf_string(io))
end
end
return out
end
Expand Down
8 changes: 8 additions & 0 deletions test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module CompletionFoo
const a=x->x
test6()=[a, a]

kwtest(; x=1, y=2, w...) = pass

array = [1, 1]
varfloat = 0.1

Expand Down Expand Up @@ -325,6 +327,12 @@ c, r, res = test_complete(s)
@test length(c) == 2
#################################################################

s = "CompletionFoo.kwtest( "
c, r, res = test_complete(s)
@test !res
@test length(c) == 1
@test contains(c[1], "x, y, w...")

# Test of inference based getfield completion
s = "\"\"."
c,r = test_complete(s)
Expand Down

0 comments on commit 7e48c5c

Please sign in to comment.