-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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][Sema] Allow missing args when solving if the completion location indicates the user may intend to write them later. #34337
Conversation
@swift-ci please test |
lib/Sema/CSSimplify.cpp
Outdated
@@ -1135,6 +1175,28 @@ class ArgumentFailureTracker : public MatchCallArgumentListener { | |||
getExtraneousArguments() const { | |||
return ExtraArguments; | |||
} | |||
|
|||
private: | |||
bool areMissingArgsInvalid(ConstraintLocator *locator) { |
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.
Maybe we should convert this into a filter over MissingArguments
in argument tracker instead and only record the ones which come before the token?
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.
Or even better - ignore missing argument recorded if it comes after the token that way destructor of the ArgumentFailureTracker
could stay untouched?
lib/Sema/CSSimplify.cpp
Outdated
SourceRange range = closure->getSourceRange(); | ||
if (range.isValid() && SM.rangeContainsCodeCompletionLoc(range)) { | ||
shouldFix = !closure->hasAnonymousClosureVars() && | ||
(!args.empty() || closure->getInLoc().isValid()); |
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.
Maybe an early return here in reverse situation instead?
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.
Would missing the single tuple argument handling below (need to expand a few lines) be a problem?
Actually I guess these cases should be exclusive.
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.
Yeah, I think that should be okay.
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.
Overall LGTM, I have left a couple of comments inline.
36f89a0
to
b8a4af2
Compare
Build failed |
b8a4af2
to
cd6f200
Compare
struct SynthesizedArg { | ||
unsigned paramIdx; | ||
AnyFunctionType::Param param; | ||
}; | ||
|
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.
This is no longer necessary (in my original changes it also tracked the index to insert the missing arg at) but I left it in for the slight readability improvement over a std::pair
(e.g. paramIdx
vs first
)
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.
That works for me, thank you!
Build failed |
@swift-ci please test |
…ion location indicates the user may intend to write them later. func foo(a: Int, b: Int) {} func foo(a: String) {} // Int and String should both be valid, despite the missing argument for the // first overload since the second arg may just have not been written yet. foo(a: <complete here> func bar(a: (Int) -> ()) {} func bar(a: (String, Int) -> ()) {} // $0 being of type String should be valid, rather than just Int, since $1 may // just have not been written yet. bar { $0.<complete here> }
cd6f200
to
15f5222
Compare
@swift-ci please test and merge |
Build failed |
Build failed |
Int
andString
members should both be prioritized for the completion below despite the missing argument for the first overload since the second argument may just have not been written yet:Similarly, members of type
String
should also be prioritized for the completion below (rather than justInt
) since the user may intend to use$1
later in the expression.