-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
@swift-ci Please smoke test |
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 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
d85e45a
to
74ade64
Compare
@ahoppen Fair enough. I added a commit to fallback to the existing behavior. WDYT? |
@swift-ci Please smoke test |
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.
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.
lib/IDE/ExprContextAnalysis.cpp
Outdated
@@ -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. |
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.
The comment now doesn’t match the Optional
return type anymore…
lib/IDE/ExprContextAnalysis.cpp
Outdated
unsigned &PosInParams) { | ||
static Optional<unsigned> | ||
getPositionInParams(DeclContext &DC, Expr *Args, Expr *CCExpr, | ||
ArrayRef<AnyFunctionType::Param> Params, bool lenient) { |
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.
Nitpick: All the other arguments are capitalized.
/*lenient=*/true); | ||
} | ||
} | ||
} |
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 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.
74ade64
to
27639c2
Compare
@swift-ci Please smoke test |
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