diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2018-09-13 11:47:48 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2018-09-13 11:47:48 +0000 |
| commit | c8758406b5685457992448fcca5b07c92c37b37b (patch) | |
| tree | 0d35cd689112b8c1ff3fe086e28b1cb353a8e4b7 /clang-tools-extra/clangd/ClangdServer.cpp | |
| parent | 778e0d24eebf6d29ef33fd61cc92724c0aead03e (diff) | |
| download | bcm5719-llvm-c8758406b5685457992448fcca5b07c92c37b37b.tar.gz bcm5719-llvm-c8758406b5685457992448fcca5b07c92c37b37b.zip | |
[clangd] Simplify cancellation public API
Summary:
Task is no longer exposed:
- task cancellation is hidden as a std::function
- task creation returns the new context directly
- checking is via free function only, with no way to avoid the context lookup
The implementation is essentially the same, but a bit terser as it's hidden.
isCancelled() is now safe to use outside any task (it returns false).
This will leave us free to sprinkle cancellation in e.g. TUScheduler without
needing elaborate test setup, and lets callers that don't cancel "just work".
Updated the docs to describe the new expected use pattern.
One thing I noticed: there's nothing async-specific about the cancellation.
Async tasks can be cancelled from any thread (typically the one that created
them), sync tasks can be cancelled from any *other* thread in the same way.
So the docs now refer to "long-running" tasks instead of async ones.
Updated usage in code complete, without any structural changes.
I didn't update all the names of the helpers in ClangdLSPServer (these will
likely be moved to JSONRPCDispatcher anyway).
Reviewers: ilya-biryukov, kadircet
Subscribers: ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits
Differential Revision: https://reviews.llvm.org/D51996
llvm-svn: 342130
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 0a8e748b2f8..20af72fb451 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -201,16 +201,16 @@ void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); } -TaskHandle ClangdServer::codeComplete(PathRef File, Position Pos, - const clangd::CodeCompleteOptions &Opts, - Callback<CodeCompleteResult> CB) { +Canceler ClangdServer::codeComplete(PathRef File, Position Pos, + const clangd::CodeCompleteOptions &Opts, + Callback<CodeCompleteResult> CB) { // Copy completion options for passing them to async task handler. auto CodeCompleteOpts = Opts; if (!CodeCompleteOpts.Index) // Respect overridden index. CodeCompleteOpts.Index = Index; - TaskHandle TH = Task::createHandle(); - WithContext ContextWithCancellation(setCurrentTask(TH)); + auto Cancelable = cancelableTask(); + WithContext ContextWithCancellation(std::move(Cancelable.first)); // Copy PCHs to avoid accessing this->PCHs concurrently std::shared_ptr<PCHContainerOperations> PCHs = this->PCHs; auto FS = FSProvider.getFileSystem(); @@ -259,7 +259,7 @@ TaskHandle ClangdServer::codeComplete(PathRef File, Position Pos, // We use a potentially-stale preamble because latency is critical here. WorkScheduler.runWithPreamble("CodeComplete", File, TUScheduler::Stale, Bind(Task, File.str(), std::move(CB))); - return TH; + return std::move(Cancelable.second); } void ClangdServer::signatureHelp(PathRef File, Position Pos, |

