Skip to content

[CodeCompletion] Don't suggest argument labels from unapplicable overload #37432

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 2 commits into from
May 18, 2021

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 14, 2021

When matching an argument to a parameter list, if there is no matching parameter, the argument list is not applicable to the parameters. In such case, code completion should not suggest argument labels of the function.

rdar://77867723

@rintaro
Copy link
Member Author

rintaro commented May 14, 2021

@swift-ci Please smoke test

@rintaro rintaro requested a review from ahoppen May 14, 2021 21:16
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

I don’t think this is an improvement in all cases. I can see that in your test case, it’s definitely what the user is expecting but when completing self.fn(cc: .up, #^OVERLOAD_LABEL^#) where the user made a typo and only typed two c, we now aren’t providing any results.

I think it would be great if we would fall back to the current behavior, if we don’t get any completions otherwise. An initial idea of mine how to implement it, would be to have a flag on getPositionInParams and the main body of analyzeApplyExpr (after the comment // Collect possible types (or labels) at the position.) toggling the behavior. If that flag is set to “strict argument label matching” and we don’t have any results at the end of analyzeApplyExpr, we just invoke the main body again with the flag set to “weak argument label matching”. What do you think?

…load

When matching an argument to a parameter list, if there is no matching
parameter, the argument list is not applicable to the parameters. In
such case, code completion should not suggest argument labels of the
function.

rdar://77867723
@rintaro rintaro force-pushed the ide-completion-rdar77867723 branch 2 times, most recently from d85e45a to 74ade64 Compare May 17, 2021 21:44
@rintaro
Copy link
Member Author

rintaro commented May 17, 2021

@ahoppen Fair enough. I added a commit to fallback to the existing behavior. WDYT?

@rintaro
Copy link
Member Author

rintaro commented May 17, 2021

@swift-ci Please smoke test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for adding the fallback option.

I’ve got three super minor nitpicks. It would be nice to fix them but if you want to get this merged soon, feel free to ignore them.

@@ -772,21 +772,20 @@ static Expr *getArgAtPosition(Expr *Args, unsigned Position) {
/// in \p Params which don't occur in \p Args.
///
/// \returns \c true if success, \c false if \p CCExpr is not a part of \p Args.
Copy link
Member

Choose a reason for hiding this comment

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

The comment now doesn’t match the Optional return type anymore…

unsigned &PosInParams) {
static Optional<unsigned>
getPositionInParams(DeclContext &DC, Expr *Args, Expr *CCExpr,
ArrayRef<AnyFunctionType::Param> Params, bool lenient) {
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: All the other arguments are capitalized.

/*lenient=*/true);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think for safety and readability it would be good to have an

assert(posInParams.size() == Candidates.size());

here.

… not found

If label-matching overload is not found, try to find a position with
lenient label matching.
@rintaro rintaro force-pushed the ide-completion-rdar77867723 branch from 74ade64 to 27639c2 Compare May 18, 2021 16:18
@rintaro
Copy link
Member Author

rintaro commented May 18, 2021

@swift-ci Please smoke test

@rintaro rintaro merged commit e7e3097 into swiftlang:main May 18, 2021
@rintaro rintaro deleted the ide-completion-rdar77867723 branch May 18, 2021 19: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