-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[CodeCompletion] Refactor how code completion results are returned to support cancellation #39631
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] Refactor how code completion results are returned to support cancellation #39631
Conversation
a729d2c to
81d3ca4
Compare
|
The previous version of this PR made code completion return an error if no code completion token was found, instead of returning empty results. It turns out that the stress tester expected empty results in that case and I’m worried changing the semantics will break clients. So I’m reverting to the original behavior of returning an empty result list in that case. |
81d3ca4 to
a2ec632
Compare
|
@swift-ci Please smoke test |
a2ec632 to
24a13ea
Compare
|
Based on some discussion with @rintaro, we agreed that the previous version of this PR was not ideal because it exposed implementation details of libIDE, such as I went a step further now and pushed the fact that the This also moves the |
24a13ea to
82bc6b2
Compare
|
@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.
Could you explain why not Result = Other.Result?
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.
It’s something to do with deleted copy constructor. IIUC we don’t want to destruct the Result in the union because it’s just uninitialized memory and it’s copy contractor might be deleted. I copied the implementation from llvm::Optional
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.
| void deliverResults(SourceKit::ConformingMethodListConsumer &SKConsumer, | |
| static void deliverResults(SourceKit::ConformingMethodListConsumer &SKConsumer, |
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.
Not used?
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.
| void deliverCodeCompleteResults(SourceKit::CodeCompletionConsumer &SKConsumer, | |
| static void deliverCodeCompleteResults(SourceKit::CodeCompletionConsumer &SKConsumer, |
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.
| void deliverResults(SourceKit::TypeContextInfoConsumer &SKConsumer, | |
| static void deliverResults(SourceKit::TypeContextInfoConsumer &SKConsumer, |
|
@swift-ci Please smoke test |
… support cancellation This refactors a bunch of code-completion methods around `performOperation` to return their results via a callback only instead of the current mixed approach of indicating failure via a return value, returning an error string as an inout parameter and success results via a callback. The new guarantee should be that the callback is always called exactly once on control flow graph. Other than a support for passing the (currently unused) cancelled state through the different instance, there should be no functionality change.
…ation We had some situations left that neither returned an error, nor called the callback with results in `performOperation`. Return an error in these and adjust the tests to correctly match the error.
…ntextInfo from SoruceKit to CompletionInstance The invocation of the code completion second pass should be implementation detail of `CompletionInstance`. Create a method on `CompletionInstance` that correctly invokes the second pass and just reutnrs the type context info results to the caller.
…mingMethodList from SoruceKit to CompletionInstance
…ompletion from SoruceKit to CompletionInstance
All users of `performCodeCompletionLikeOperation` have been migrated to dedicated methods on `CompletionInstance`.
…onInstance instead of generic performOperation We are migrating all users of `performOperation` to dedicated methods on `CodeCompletionInstance`. Do the same in `swift-ide-test`.
…pletionInstance instead of generic performOperation
…onInstance instead of generic performOperation
All users of `CompletionInstance::performOperation` have been migrated to dedicated methods. `performOperation` with its callback that needs to invoke the second pass is now an implementation detail of `CompletionInstance`.
540bef8 to
95ae8a4
Compare
|
Resolved a memory error in @swift-ci Please smoke test |
ee77b3f to
c9f5331
Compare
|
@swift-ci Please smoke test |
| // If we're expecting a standard library, but there either isn't one, or it | ||
| // failed to load, let's bail early and hand back an empty completion | ||
| // result to avoid any downstream crashes. | ||
| if (CI.loadStdlibIfNeeded()) | ||
| return true; | ||
| if (CI.loadStdlibIfNeeded()) { | ||
| Callback(CancellableResult<CompletionInstanceResult>::failure( | ||
| "failed to load the standard library")); | ||
| return; | ||
| } |
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.
Should the comment be updated here?
FWIW I think this was the only client that was handling a stdlib load failure different to other setup failures, we may be able to call loadStdlibIfNeeded from within CompilerInstance::setup now, which would probably help catch more cases of crashing when the stdlib fails to load.
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.
Doing a quick search for loadStdlibIfNeeded, there are a couple more places that have specific handling for it and some of them don't seem to call CompilerInstance::setup at all. Unifying those might be a good task for another PR but I think it’s out of scope for this one.
This refactors a bunch of code-completion methods around
performOperationto return their results via a callback only instead of the current mixed approach of indicating failure via a return value, returning an error string as an inout parameter and success results via a callback. The new guarantee should be that the callback is always called exactly once on control flow graph.