kadircet updated this revision to Diff 306839. kadircet marked 3 inline comments as done. kadircet added a comment.
- Address comments Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91860/new/ https://reviews.llvm.org/D91860 Files: clang-tools-extra/clangd/CMakeLists.txt clang-tools-extra/clangd/index/ProjectAware.cpp clang-tools-extra/clangd/index/ProjectAware.h clang-tools-extra/clangd/tool/ClangdMain.cpp
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -555,6 +555,27 @@ const char TestScheme::TestDir[] = "/clangd-test"; #endif +std::unique_ptr<SymbolIndex> +loadExternalIndex(const Config::ExternalIndexSpec &External, + AsyncTaskRunner &Tasks) { + switch (External.Kind) { + case Config::ExternalIndexSpec::Server: + log("Associating {0} with remote index at {1}.", External.MountPoint, + External.Location); + return remote::getClient(External.Location, External.MountPoint); + case Config::ExternalIndexSpec::File: + log("Associating {0} with monolithic index at {1}.", External.MountPoint, + External.Location); + auto NewIndex = std::make_unique<SwapIndex>(std::make_unique<MemIndex>()); + Tasks.runAsync("Load-index:" + External.Location, + [File = External.Location, PlaceHolder = NewIndex.get()] { + if (auto Idx = loadIndex(File, /*UseDex=*/true)) + PlaceHolder->reset(std::move(Idx)); + }); + return std::move(NewIndex); + } + llvm_unreachable("Invalid ExternalIndexKind."); +} } // namespace } // namespace clangd } // namespace clang @@ -762,7 +783,7 @@ } #endif Opts.BackgroundIndex = EnableBackgroundIndex; - auto PAI = createProjectAwareIndex(); + auto PAI = createProjectAwareIndex(loadExternalIndex); if (StaticIdx) { IdxStack.emplace_back(std::move(StaticIdx)); IdxStack.emplace_back( Index: clang-tools-extra/clangd/index/ProjectAware.h =================================================================== --- clang-tools-extra/clangd/index/ProjectAware.h +++ clang-tools-extra/clangd/index/ProjectAware.h @@ -23,11 +23,11 @@ using IndexFactory = std::function<std::unique_ptr<SymbolIndex>( const Config::ExternalIndexSpec &, AsyncTaskRunner &)>; -/// Returns an index that answers queries using external indices. IndexGenerator -/// can be used to customize how to generate an index from an external source. -/// The default implementation loads the index asynchronously on the -/// AsyncTaskRunner. The index will appear empty until loaded. -std::unique_ptr<SymbolIndex> createProjectAwareIndex(IndexFactory = nullptr); +/// Returns an index that answers queries using external indices. IndexFactory +/// specifies how to generate an index from an external source. +/// IndexFactory must be injected because this code cannot depend on the remote +/// index client. +std::unique_ptr<SymbolIndex> createProjectAwareIndex(IndexFactory); } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/index/ProjectAware.cpp =================================================================== --- clang-tools-extra/clangd/index/ProjectAware.cpp +++ clang-tools-extra/clangd/index/ProjectAware.cpp @@ -15,7 +15,6 @@ #include "index/Serialization.h" #include "index/Symbol.h" #include "index/SymbolID.h" -#include "index/remote/Client.h" #include "support/Logger.h" #include "support/Threading.h" #include "support/Trace.h" @@ -124,33 +123,11 @@ Entry.first->getSecond() = Gen(External, Tasks); return Entry.first->second.get(); } - -std::unique_ptr<SymbolIndex> -defaultFactory(const Config::ExternalIndexSpec &External, - AsyncTaskRunner &Tasks) { - switch (External.Kind) { - case Config::ExternalIndexSpec::Server: - log("Associating {0} with remote index at {1}.", External.MountPoint, - External.Location); - return remote::getClient(External.Location, External.MountPoint); - case Config::ExternalIndexSpec::File: - log("Associating {0} with monolithic index at {1}.", External.MountPoint, - External.Location); - auto NewIndex = std::make_unique<SwapIndex>(std::make_unique<MemIndex>()); - Tasks.runAsync("Load-index:" + External.Location, - [File = External.Location, PlaceHolder = NewIndex.get()] { - if (auto Idx = loadIndex(File, /*UseDex=*/true)) - PlaceHolder->reset(std::move(Idx)); - }); - return std::move(NewIndex); - } - llvm_unreachable("Invalid ExternalIndexKind."); -} } // namespace std::unique_ptr<SymbolIndex> createProjectAwareIndex(IndexFactory Gen) { - return std::make_unique<ProjectAwareIndex>(Gen ? std::move(Gen) - : defaultFactory); + assert(Gen); + return std::make_unique<ProjectAwareIndex>(std::move(Gen)); } } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/CMakeLists.txt +++ clang-tools-extra/clangd/CMakeLists.txt @@ -150,7 +150,6 @@ clangTidy ${ALL_CLANG_TIDY_CHECKS} - clangdRemoteIndex clangdSupport )
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits