Skip to content

Commit 536a1b0

Browse files
committed
[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
1 parent fc6677f commit 536a1b0

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ ClangdServer::Options::operator TUScheduler::Options() const {
139139
ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
140140
const ThreadsafeFS &TFS, const Options &Opts,
141141
Callbacks *Callbacks)
142-
: ConfigProvider(Opts.ConfigProvider), TFS(TFS), ServerCallbacks(Callbacks),
142+
: ConfigProvider(Opts.ConfigProvider), CDB(CDB), TFS(TFS),
143+
ServerCallbacks(Callbacks),
143144
DynamicIdx(Opts.BuildDynamicSymbolIndex
144145
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
145146
Opts.CollectMainFileRefs)
@@ -870,6 +871,7 @@ Context ClangdServer::createProcessingContext(PathRef File) const {
870871
LLVM_NODISCARD bool
871872
ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
872873
return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) &&
874+
CDB.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) &&
873875
(!BackgroundIdx ||
874876
BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds));
875877
}

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ class ClangdServer {
362362
Context createProcessingContext(PathRef) const;
363363
config::Provider *ConfigProvider = nullptr;
364364

365+
const GlobalCompilationDatabase &CDB;
365366
const ThreadsafeFS &TFS;
366367
Callbacks *ServerCallbacks = nullptr;
367368
mutable std::mutex ConfigDiagnosticsMu;

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,5 +636,11 @@ tooling::CompileCommand DelegatingCDB::getFallbackCommand(PathRef File) const {
636636
return Base->getFallbackCommand(File);
637637
}
638638

639+
bool DelegatingCDB::blockUntilIdle(Deadline D) const {
640+
if (!Base)
641+
return true;
642+
return Base->blockUntilIdle(D);
643+
}
644+
639645
} // namespace clangd
640646
} // namespace clang

clang-tools-extra/clangd/GlobalCompilationDatabase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class GlobalCompilationDatabase {
5151
/// Clangd should treat the results as unreliable.
5252
virtual tooling::CompileCommand getFallbackCommand(PathRef File) const;
5353

54+
/// If the CDB does any asynchronous work, wait for it to complete.
55+
/// For use in tests.
56+
virtual bool blockUntilIdle(Deadline D) const { return true; }
57+
5458
using CommandChanged = Event<std::vector<std::string>>;
5559
/// The callback is notified when files may have new compile commands.
5660
/// The argument is a list of full file paths.
@@ -75,6 +79,8 @@ class DelegatingCDB : public GlobalCompilationDatabase {
7579

7680
tooling::CompileCommand getFallbackCommand(PathRef File) const override;
7781

82+
bool blockUntilIdle(Deadline D) const override;
83+
7884
private:
7985
const GlobalCompilationDatabase *Base;
8086
std::unique_ptr<GlobalCompilationDatabase> BaseOwner;

0 commit comments

Comments
 (0)