sammccall created this revision. sammccall added a reviewer: kadircet. Herald added subscribers: usaxena95, arphaman. sammccall requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang.
In preparation for moving DirectoryBasedCompilationDatabase broadcasting off the main thread. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D94603 Files: clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/ClangdServer.h clang-tools-extra/clangd/GlobalCompilationDatabase.cpp clang-tools-extra/clangd/GlobalCompilationDatabase.h Index: clang-tools-extra/clangd/GlobalCompilationDatabase.h =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.h +++ clang-tools-extra/clangd/GlobalCompilationDatabase.h @@ -51,6 +51,10 @@ /// 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 @@ tooling::CompileCommand getFallbackCommand(PathRef File) const override; + bool blockUntilIdle(Deadline D) const override; + private: const GlobalCompilationDatabase *Base; std::unique_ptr<GlobalCompilationDatabase> BaseOwner; Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -635,5 +635,11 @@ return Base->getFallbackCommand(File); } +bool DelegatingCDB::blockUntilIdle(Deadline D) const { + if (!Base) + return true; + return Base->blockUntilIdle(D); +} + } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/clangd/ClangdServer.h +++ clang-tools-extra/clangd/ClangdServer.h @@ -362,6 +362,7 @@ Context createProcessingContext(PathRef) const; config::Provider *ConfigProvider = nullptr; + const GlobalCompilationDatabase &CDB; const ThreadsafeFS &TFS; Callbacks *ServerCallbacks = nullptr; mutable std::mutex ConfigDiagnosticsMu; Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -139,7 +139,8 @@ 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) @@ -873,6 +874,7 @@ LLVM_NODISCARD bool ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) { return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) && + CDB.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) && (!BackgroundIdx || BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds)); }
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.h =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.h +++ clang-tools-extra/clangd/GlobalCompilationDatabase.h @@ -51,6 +51,10 @@ /// 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 @@ tooling::CompileCommand getFallbackCommand(PathRef File) const override; + bool blockUntilIdle(Deadline D) const override; + private: const GlobalCompilationDatabase *Base; std::unique_ptr<GlobalCompilationDatabase> BaseOwner; Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -635,5 +635,11 @@ return Base->getFallbackCommand(File); } +bool DelegatingCDB::blockUntilIdle(Deadline D) const { + if (!Base) + return true; + return Base->blockUntilIdle(D); +} + } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/clangd/ClangdServer.h +++ clang-tools-extra/clangd/ClangdServer.h @@ -362,6 +362,7 @@ Context createProcessingContext(PathRef) const; config::Provider *ConfigProvider = nullptr; + const GlobalCompilationDatabase &CDB; const ThreadsafeFS &TFS; Callbacks *ServerCallbacks = nullptr; mutable std::mutex ConfigDiagnosticsMu; Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -139,7 +139,8 @@ 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) @@ -873,6 +874,7 @@ LLVM_NODISCARD bool ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) { return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) && + CDB.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) && (!BackgroundIdx || BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds)); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits