Skip to content

[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

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 13, 2024

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.

@ahoppen
Copy link
Member Author

ahoppen commented Feb 13, 2024

@swift-ci Please smoke test

Comment on lines 289 to 290
if (auto ParentExpr = CS.getParentExpr(ParentCall);
ParentExpr && CS.getParentExpr(ParentCall)->getArgs()) {
Copy link
Member

@rintaro rintaro Feb 14, 2024

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:

Suggested change
if (auto ParentExpr = CS.getParentExpr(ParentCall);
ParentExpr && CS.getParentExpr(ParentCall)->getArgs()) {
if (auto ParentExpr = CS.getParentExpr(ParentCall);
ParentExpr->getArgs()) {

?

Copy link
Member Author

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 👍🏽

@ahoppen ahoppen force-pushed the ahoppen/nested-call-completion branch from eccec44 to eb2704b Compare February 14, 2024 21:15
@ahoppen
Copy link
Member Author

ahoppen commented Feb 14, 2024

@swift-ci Please smoke test

Comment on lines 129 to 133
/// 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()) {
Copy link
Member

@rintaro rintaro Feb 14, 2024

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.

Copy link
Member Author

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.

@ahoppen ahoppen force-pushed the ahoppen/nested-call-completion branch from eb2704b to 3d05173 Compare February 17, 2024 00:01
@ahoppen
Copy link
Member Author

ahoppen commented Feb 17, 2024

@swift-ci Please smoke test

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Feb 21, 2024

@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.
@ahoppen ahoppen force-pushed the ahoppen/nested-call-completion branch from 3d05173 to 17520dc Compare February 22, 2024 02:53
@ahoppen
Copy link
Member Author

ahoppen commented Feb 22, 2024

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 22, 2024

@swift-ci Please test Windows

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

LGTM

@ahoppen ahoppen merged commit 0b580f7 into swiftlang:main Feb 26, 2024
@ahoppen ahoppen deleted the ahoppen/nested-call-completion branch February 26, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants