-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Always suggest call pattern for nested function calls #71587
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
[CodeCompletion] Always suggest call pattern for nested function calls #71587
Conversation
@swift-ci Please smoke test |
lib/IDE/ArgumentCompletion.cpp
Outdated
if (auto ParentExpr = CS.getParentExpr(ParentCall); | ||
ParentExpr && CS.getParentExpr(ParentCall)->getArgs()) { |
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.
Does this cover multi-level nested cases like foo(x: bar.baz(<HERE>
, and foo(x: 1 + bar(<HERE>
? Adding test cases would be nice.
Also, do you mean:
if (auto ParentExpr = CS.getParentExpr(ParentCall); | |
ParentExpr && CS.getParentExpr(ParentCall)->getArgs()) { | |
if (auto ParentExpr = CS.getParentExpr(ParentCall); | |
ParentExpr->getArgs()) { |
?
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.
I added test cases. It did work but I changed it to be a search through all parent expressions anyway. That seems more failure proof. Good idea 👍🏽
eccec44
to
eb2704b
Compare
@swift-ci Please smoke test |
lib/IDE/ArgumentCompletion.cpp
Outdated
/// Returns whether `E` has a parent expression with arguments. | ||
static bool hasParentCallLikeExpr(Expr *E, ConstraintSystem &CS) { | ||
E = CS.getParentExpr(E); | ||
while (E) { | ||
if (E->getArgs()) { |
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.
I came up with other cases
let _ = [
foo: bar(#^HERE^#,
baz: 1
]
Same for tuples. Does it make sense to add check for TupleExpr
/ArrayExpr
/DictionaryExpr
as well?
Actually, it's not only expressions, any comma separated syntax might be affected e.g.
if let foo = bar(#^HERE^#, foo > baz { ...
But I think it's okay to ignore them for now.
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.
Oh, good catch. I added those cases. I also think it’s OK to ignore the if
conditions etc for now. We provide argument completions still, so the fallback if we don’t offer the pattern isn’t terrible.
eb2704b
to
3d05173
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
When completing in cases like `bar(arg: foo(|, option: 1)`, we don’t know if `option` belongs to the call to `foo` or `bar`. Be defensive and also suggest the signature.
3d05173
to
17520dc
Compare
@swift-ci Please smoke test |
@swift-ci Please test Windows |
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.
LGTM
When completing in cases like
bar(arg: foo(|, option: 1)
, we don’t know ifoption
belongs to the call tofoo
orbar
. Be defensive and also suggest the signature.