-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Some refactorings surrounding solver-based completion #41885
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] Some refactorings surrounding solver-based completion #41885
Conversation
3011ff6
to
fe46180
Compare
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
… completion callbacks
…all solver-based completion kinds
fe46180
to
03d819f
Compare
@swift-ci Please smoke test |
// func foo(fn: () async -> Void) | ||
// foo { <HERE> } | ||
// In this case, the closure is wrapped with a 'FunctionConversionExpr' | ||
// which has 'async' function type. |
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 assume a type-checked version of the AST, is that always the case?
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 believe so. The call side inside CompletionLookup
is intended for the legacy code completion, which works on a type-checked AST and https://github.com/apple/swift/pull/41885/files/03d819f442f05b58f6a2b1816b2e280292db5329#diff-3088e637c4f06d0fc6cb38370068cd6fa6fe8dcaa10ec35c9086602c59eaba17R149 works on the already type-checked part of the AST to determine async-ness after failing to determine async-ness from the solution.
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.
Sounds good, just double-checking! :)
/// Called for each solution produced while type-checking an expression | ||
/// that the code completion expression participates in. | ||
virtual void sawSolution(const constraints::Solution &solution) { | ||
GotCallback = 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.
This looks suspicious - there is no way to ensure that each override calls TypeCheckCompletionCallback::sawSolution(solution)
internally. I see that they currently do but it only takes one to go unnoticed... I'd like to suggest virtual
to be removed from this method, and instead be used on a protected
sawSolutionImpl(const Solution &)
which is going to be called from this one.
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.
Sounds like a good idea. I’ll do that.
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.
Implemented in 3597652
…mpl from subclasses This eliminates a source of bugs if subclasses of `TypeCheckCompletionCallback` forget to call the superclass’s implementation of `sawSolution` from their overridden method.
@swift-ci Please smoke test |
Perform a couple of refactoring for solver-based completion, with the goal of sharing more code between the different completion kinds:
TypeCheckCompletionCallbacks
from Sema to IDEUnresolvedType
and some had fewer fallback mechanisms to retrieve the type, have one implementation that does everythingExprCompletion
checked whether the surrounding context is async, I don’t have any failing test cases for the other completion kinds but it definitely makes sense for them to share the same logic to determine whether the surrounding context is async