-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use type inference to determine the call signature for method completion. #11679
Conversation
@@ -203,35 +203,77 @@ function find_start_brace(s::AbstractString) | |||
end | |||
|
|||
# Returns the value in a expression if sym is defined in current namespace fn. | |||
# The vars argument is a dictionary that contains all variables in the ex_org |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
1940b8f
to
53bad69
Compare
@tkelman thank you for the reminder, I have pushed a new version with fixed whitespaces and added test cases. |
I'll try to take a look at this later this weekend. |
Thank you @blakejohnson, the Travis/Appveyor failures are unrelated. |
@blakejohnson, the code is not versatile enough to handle all cases, so hold off reviewing this. |
6b13082
to
603d16c
Compare
I finally got around to rebase and solve this PR in a better way. @blakejohnson Could you review this? |
Bump, anyone willing to review. |
Sorry, if no one gets to it before me, I'll try to have a look early this week. |
Bump. |
So, my reading of this change is that it appears correct. I always have some trouble reading code that does expression parsing, though, because it is never particularly clear what you are extracting in statements like How do people feel about REPL completion behavior depending on type inference? There has previously been resistance to making program behavior depend on inference. This seems like a different category, though, since the programs you write aren't changed, but only the help you receive while writing them. |
@@ -222,14 +222,61 @@ get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (fn.(sym), true) : (nothing, f | |||
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (fn.(sym.value), true) : (nothing, false) | |||
get_value(sym, fn) = sym, true | |||
|
|||
# Return the value of a getfield call expression | |||
function get_value_getfield(ex::Expr, fn) | |||
val, found = get_value_getfield(ex.args[2],fn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we help the reader with a comment about what is contained in ex.args[2]
and ex.args[3]
?
Thank you, @dhoegh, for including some thorough tests with this change. |
Since this is interactive, the inference issue seems less critical here. Though hypothetically could user programs hook into this and try to use it for other purposes? Maybe not worth worrying about. |
9cf4959
to
9e41f5e
Compare
I have added further comments, to try to clarify what is happening. |
It can always call type inference directly, e.g. |
Ah yeah, duh. Nevermind then. This looks okay to me, shall we merge? |
Yes, I think this is good to merge.
|
…ove non matching methods. Add test for the new functionality, fix JuliaLang#6338.
9e41f5e
to
f8196cc
Compare
I have just squashed the commits, so this should be good to merge. |
Use type inference to determine the call signature for method completion.
Cool, this is a nice thing to have. |
Thank you, @blakejohnson, for the review and merge. |
This pull implement method completion using type inference to determine the input types for a function call, Second case in #6338. This means the method completion suggestion removes the methods not appropriate for the function call, see:
The only thing I do not like about the implementation, is the need for eval an expression of the arguments into an anonymous function, see line:julia/base/REPLCompletions.jl
Line 273 in 1940b8f
LambdaStaticData
manually for the anonymous function, anyone know how this could be done?It only analyse function arguments that is a call or is lowered to a call. Hence this do not work when the arguments is an expression. Example the time macro return an expression. I have also added this as a test case in https://github.com/dhoegh/julia/blob/603d16c7742fed2b10106402ec7284cf0e7c1f6e/test/replcompletions.jl#L292.
cc @blakejohnson could you review this, you reviewed similar additions in #9676?
Further work on this pull includesMake tests