[clang-tools-extra] 536a1b0 - [clangd] Allow CDBs to have background work to block on.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 20 02:11:37 PST 2021
Author: Sam McCall
Date: 2021-01-20T11:11:01+01:00
New Revision: 536a1b0ea21163eaee53652c527ea20cf45bc675
URL: https://github.com/llvm/llvm-project/commit/536a1b0ea21163eaee53652c527ea20cf45bc675
DIFF: https://github.com/llvm/llvm-project/commit/536a1b0ea21163eaee53652c527ea20cf45bc675.diff
LOG: [clangd] Allow CDBs to have background work to block on.
In preparation for moving DirectoryBasedCompilationDatabase broadcasting off
the main thread.
Differential Revision: https://reviews.llvm.org/D94603
Added:
Modified:
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/GlobalCompilationDatabase.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index a76250fa168e7..0818d08811e0d 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -139,7 +139,8 @@ ClangdServer::Options::operator TUScheduler::Options() const {
ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
const ThreadsafeFS &TFS, const Options &Opts,
Callbacks *Callbacks)
- : ConfigProvider(Opts.ConfigProvider), TFS(TFS), ServerCallbacks(Callbacks),
+ : ConfigProvider(Opts.ConfigProvider), CDB(CDB), TFS(TFS),
+ ServerCallbacks(Callbacks),
DynamicIdx(Opts.BuildDynamicSymbolIndex
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
Opts.CollectMainFileRefs)
@@ -870,6 +871,7 @@ Context ClangdServer::createProcessingContext(PathRef File) const {
LLVM_NODISCARD bool
ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) &&
+ CDB.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) &&
(!BackgroundIdx ||
BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds));
}
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index ff2fc85781038..d10c54f402b42 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -362,6 +362,7 @@ class ClangdServer {
Context createProcessingContext(PathRef) const;
config::Provider *ConfigProvider = nullptr;
+ const GlobalCompilationDatabase &CDB;
const ThreadsafeFS &TFS;
Callbacks *ServerCallbacks = nullptr;
mutable std::mutex ConfigDiagnosticsMu;
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index fde4e56ac72d8..457cdef2bd8b5 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -636,5 +636,11 @@ tooling::CompileCommand DelegatingCDB::getFallbackCommand(PathRef File) const {
return Base->getFallbackCommand(File);
}
+bool DelegatingCDB::blockUntilIdle(Deadline D) const {
+ if (!Base)
+ return true;
+ return Base->blockUntilIdle(D);
+}
+
} // namespace clangd
} // namespace clang
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.h b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
index 125bd77a52073..d009905bbecf2 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -51,6 +51,10 @@ class GlobalCompilationDatabase {
/// Clangd should treat the results as unreliable.
virtual tooling::CompileCommand getFallbackCommand(PathRef File) const;
+ /// If the CDB does any asynchronous work, wait for it to complete.
+ /// For use in tests.
+ virtual bool blockUntilIdle(Deadline D) const { return true; }
+
using CommandChanged = Event<std::vector<std::string>>;
/// The callback is notified when files may have new compile commands.
/// The argument is a list of full file paths.
@@ -75,6 +79,8 @@ class DelegatingCDB : public GlobalCompilationDatabase {
tooling::CompileCommand getFallbackCommand(PathRef File) const override;
+ bool blockUntilIdle(Deadline D) const override;
+
private:
const GlobalCompilationDatabase *Base;
std::unique_ptr<GlobalCompilationDatabase> BaseOwner;
More information about the cfe-commits
mailing list