diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -185,10 +185,6 @@ /// regions in the document. bool PublishInactiveRegions = false; - /// Whether to run preamble indexing asynchronously in an independent - /// thread. - bool AsyncPreambleIndexing = false; - explicit operator TUScheduler::Options() const; }; // Sensible default options for use in tests. diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -67,11 +67,10 @@ UpdateIndexCallbacks(FileIndex *FIndex, ClangdServer::Callbacks *ServerCallbacks, const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks, - bool CollectInactiveRegions, - const ClangdServer::Options &Opts) - : FIndex(FIndex), ServerCallbacks(ServerCallbacks), - TFS(TFS), Stdlib{std::make_shared()}, Tasks(Tasks), - CollectInactiveRegions(CollectInactiveRegions), Opts(Opts) {} + bool CollectInactiveRegions) + : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS), + Stdlib{std::make_shared()}, Tasks(Tasks), + CollectInactiveRegions(CollectInactiveRegions) {} void onPreambleAST( PathRef Path, llvm::StringRef Version, CapturedASTCtx ASTCtx, @@ -94,7 +93,7 @@ ASTCtx.getPreprocessor(), *CanonIncludes); }; - if (Opts.AsyncPreambleIndexing && Tasks) { + if (Tasks) { Tasks->runAsync("Preamble indexing for:" + Path + Version, std::move(Task)); } else @@ -164,7 +163,6 @@ std::shared_ptr Stdlib; AsyncTaskRunner *Tasks; bool CollectInactiveRegions; - const ClangdServer::Options &Opts; }; class DraftStoreFS : public ThreadsafeFS { @@ -229,7 +227,7 @@ std::make_unique( DynamicIdx.get(), Callbacks, TFS, IndexTasks ? &*IndexTasks : nullptr, - PublishInactiveRegions, Opts)); + PublishInactiveRegions)); // Adds an index to the stack, at higher priority than existing indexes. auto AddIndex = [&](SymbolIndex *Idx) { if (this->Index != nullptr) { diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -11,6 +11,8 @@ #include "Compiler.h" #include "Config.h" #include "Diagnostics.h" +#include "FS.h" +#include "FeatureModule.h" #include "Headers.h" #include "Protocol.h" #include "SourceCode.h" @@ -21,8 +23,10 @@ #include "support/ThreadsafeFS.h" #include "support/Trace.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/Type.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticLex.h" +#include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" @@ -51,12 +55,17 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" +#include +#include #include +#include +#include #include #include #include @@ -616,7 +625,8 @@ }); llvm::IntrusiveRefCntPtr PreambleDiagsEngine = CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(), - &PreambleDiagnostics, false); + &PreambleDiagnostics, + /*ShouldOwnClient=*/false); const Config &Cfg = Config::current(); PreambleDiagnostics.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) { @@ -663,8 +673,12 @@ auto BuiltPreamble = PrecompiledPreamble::Build( CI, ContentsBuffer.get(), Bounds, *PreambleDiagsEngine, Stats ? TimedFS : StatCacheFS, std::make_shared(), - StoreInMemory, /*StoragePath=*/StringRef(), CapturedInfo); + StoreInMemory, /*StoragePath=*/"", CapturedInfo); PreambleTimer.stopTimer(); + // Reset references to ref-counted-ptrs before executing the callbacks, to + // prevent resetting them concurrently. + PreambleDiagsEngine.reset(); + CI.DiagnosticOpts.reset(); // When building the AST for the main file, we do want the function // bodies.