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

REPL: enable MethodCompletions after keyword arguments #38106

Merged
merged 2 commits into from
Nov 17, 2020

Conversation

aviatesk
Copy link
Sponsor Member

@aviatesk aviatesk commented Oct 20, 2020

With this PR, we can have completions for e.g. foo(1, kw1 = 1, ...) when we have foo(a; kw1 = 1, kws...) = ...:

julia> foo(a; kw1 = 1, kws...) = return
foo (generic function with 1 method)

julia> foo(a::Integer; kw1 = 1, kws...) = return
foo (generic function with 2 methods)

julia> foo(1, )

foo(a::Integer; kw1, kws...) in Main at none:1 foo(a; kw1, kws...) in Main at none:1
julia> foo(1, kw1 = nothing, )

foo(a::Integer; kw1, kws...) in Main at none:1 foo(a; kw1, kws...) in Main at none:1
julia> foo(1, kw1 = nothing, kw = '1', )

foo(a::Integer; kw1, kws...) in Main at none:1 foo(a; kw1, kws...) in Main at none:1

It will also benefit certain frontends like Juno (and possibly julia-vscode if we merge this PR), allowing them to predicate return type on completion signatures from keyword method.

@@ -40,6 +40,7 @@ struct MethodCompletion <: Completion
func
input_types::Type
method::Method
orig_method::Union{Nothing,Method} # if `method` is a keyword method, keep the original method for sensible printing
Copy link
Sponsor Member Author

@aviatesk aviatesk Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, the completion would look like below and imho looks less friendly (while it's the internal truth):

julia> foo(1, kw1 = nothing, )

(::var"#foo##kw")(::Any, ::typeof(foo), a::Integer) in Main at none:1 (::var"#foo##kw")(::Any, ::typeof(foo), a) in Main at none:1

q: is there a way to retrieve the original Method object from its keyword-arg Method ? Then we don't need this additional field.

@aviatesk aviatesk force-pushed the kwmethodcomp branch 4 times, most recently from 28b97d2 to 5363d25 Compare October 27, 2020 00:53
@rfourquet rfourquet added the stdlib:REPL Julia's REPL (Read Eval Print Loop) label Oct 27, 2020
@fredrikekre
Copy link
Member

Fixes #37607?

@aviatesk
Copy link
Sponsor Member Author

yep

@aviatesk aviatesk force-pushed the kwmethodcomp branch 2 times, most recently from 5029fec to 1c943cd Compare October 29, 2020 09:25
@aviatesk
Copy link
Sponsor Member Author

@JeffBezanson could you have a review on this ?

@aviatesk aviatesk force-pushed the kwmethodcomp branch 4 times, most recently from 036b283 to 0bcb653 Compare November 5, 2020 06:28
@aviatesk aviatesk force-pushed the kwmethodcomp branch 2 times, most recently from bd11a66 to a9e6c17 Compare November 11, 2020 14:16
@aviatesk
Copy link
Sponsor Member Author

Could someone review this ? Maybe @JeffBezanson @pfitzseb or @KristofferC ?

@KristofferC
Copy link
Sponsor Member

Tests look ok and it's just an interactive feature so I'll just merge this after CI is green.

@aviatesk
Copy link
Sponsor Member Author

Thanks, I just added some type annotations to improve type stabilities around complete_methods

@aviatesk
Copy link
Sponsor Member Author

The failures in CI are unrelated:

    REPL                            |     1223                    3      1226
    Profile                         |       22     1      1                24
    Serialization                   |      119                            119

@aviatesk
Copy link
Sponsor Member Author

@KristofferC bump.

@KristofferC KristofferC merged commit 382a665 into JuliaLang:master Nov 17, 2020
@aviatesk aviatesk deleted the kwmethodcomp branch November 17, 2020 08:25
aviatesk added a commit to JunoLab/FuzzyCompletions.jl that referenced this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib:REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants