Index: clangd/ClangdLSPServer.h =================================================================== --- clangd/ClangdLSPServer.h +++ clangd/ClangdLSPServer.h @@ -135,21 +135,17 @@ /// Returns a CDB that should be used to get compile commands for the /// current instance of ClangdLSPServer. - GlobalCompilationDatabase &getCDB(); + GlobalCompilationDatabase &getCDB() { return *CDB; } private: CompilationDB(std::unique_ptr CDB, - std::unique_ptr CachingCDB, bool IsDirectoryBased) - : CDB(std::move(CDB)), CachingCDB(std::move(CachingCDB)), - IsDirectoryBased(IsDirectoryBased) {} + : CDB(std::move(CDB)), IsDirectoryBased(IsDirectoryBased) {} // if IsDirectoryBased is true, an instance of InMemoryCDB. // If IsDirectoryBased is false, an instance of DirectoryBasedCDB. // unique_ptr CDB; std::unique_ptr CDB; - // Non-null only for directory-based CDB - std::unique_ptr CachingCDB; bool IsDirectoryBased; }; Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -783,7 +783,7 @@ } ClangdLSPServer::CompilationDB ClangdLSPServer::CompilationDB::makeInMemory() { - return CompilationDB(llvm::make_unique(), nullptr, + return CompilationDB(llvm::make_unique(), /*IsDirectoryBased=*/false); } @@ -792,16 +792,13 @@ Optional CompileCommandsDir) { auto CDB = llvm::make_unique( std::move(CompileCommandsDir)); - auto CachingCDB = llvm::make_unique(*CDB); - return CompilationDB(std::move(CDB), std::move(CachingCDB), + return CompilationDB(std::move(CDB), /*IsDirectoryBased=*/true); } void ClangdLSPServer::CompilationDB::invalidate(PathRef File) { if (!IsDirectoryBased) static_cast(CDB.get())->invalidate(File); - else - CachingCDB->invalidate(File); } bool ClangdLSPServer::CompilationDB::setCompilationCommandForFile( @@ -826,7 +823,6 @@ } static_cast(CDB.get()) ->setExtraFlagsForFile(File, std::move(ExtraFlags)); - CachingCDB->invalidate(File); } void ClangdLSPServer::CompilationDB::setCompileCommandsDir(Path P) { @@ -837,13 +833,6 @@ } static_cast(CDB.get()) ->setCompileCommandsDir(P); - CachingCDB->clear(); -} - -GlobalCompilationDatabase &ClangdLSPServer::CompilationDB::getCDB() { - if (CachingCDB) - return *CachingCDB; - return *CDB; } } // namespace clangd Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -728,9 +728,9 @@ // Retain the results we might want. for (unsigned I = 0; I < NumResults; ++I) { auto &Result = InResults[I]; - // Drop hidden items which cannot be found by lookup after completion. - // Exception: some items can be named by using a qualifier. - if (Result.Hidden && (!Result.Qualifier || Result.QualifierIsInformative)) + // Class members that are shadowed by subclasses are usually noise. + if (Result.Hidden && Result.Declaration && + Result.Declaration->isCXXClassMember()) continue; if (!Opts.IncludeIneligibleResults && (Result.Availability == CXAvailability_NotAvailable || Index: clangd/GlobalCompilationDatabase.h =================================================================== --- clangd/GlobalCompilationDatabase.h +++ clangd/GlobalCompilationDatabase.h @@ -86,33 +86,6 @@ llvm::Optional CompileCommandsDir; }; -/// A wrapper around GlobalCompilationDatabase that caches the compile commands. -/// Note that only results of getCompileCommand are cached. -class CachingCompilationDb : public GlobalCompilationDatabase { -public: - explicit CachingCompilationDb(const GlobalCompilationDatabase &InnerCDB); - - /// Gets compile command for \p File from cache or CDB if it's not in the - /// cache. - llvm::Optional - getCompileCommand(PathRef File) const override; - - /// Forwards to the inner CDB. Results of this function are not cached. - tooling::CompileCommand getFallbackCommand(PathRef File) const override; - - /// Removes an entry for \p File if it's present in the cache. - void invalidate(PathRef File); - - /// Removes all cached compile commands. - void clear(); - -private: - const GlobalCompilationDatabase &InnerCDB; - mutable std::mutex Mut; - mutable llvm::StringMap> - Cached; /* GUARDED_BY(Mut) */ -}; - /// Gets compile args from an in-memory mapping based on a filepath. Typically /// used by clients who provide the compile commands themselves. class InMemoryCompilationDb : public GlobalCompilationDatabase { Index: clangd/GlobalCompilationDatabase.cpp =================================================================== --- clangd/GlobalCompilationDatabase.cpp +++ clangd/GlobalCompilationDatabase.cpp @@ -116,38 +116,6 @@ return nullptr; } -CachingCompilationDb::CachingCompilationDb( - const GlobalCompilationDatabase &InnerCDB) - : InnerCDB(InnerCDB) {} - -Optional -CachingCompilationDb::getCompileCommand(PathRef File) const { - std::unique_lock Lock(Mut); - auto It = Cached.find(File); - if (It != Cached.end()) - return It->second; - - Lock.unlock(); - Optional Command = InnerCDB.getCompileCommand(File); - Lock.lock(); - return Cached.try_emplace(File, std::move(Command)).first->getValue(); -} - -tooling::CompileCommand -CachingCompilationDb::getFallbackCommand(PathRef File) const { - return InnerCDB.getFallbackCommand(File); -} - -void CachingCompilationDb::invalidate(PathRef File) { - std::unique_lock Lock(Mut); - Cached.erase(File); -} - -void CachingCompilationDb::clear() { - std::unique_lock Lock(Mut); - Cached.clear(); -} - Optional InMemoryCompilationDb::getCompileCommand(PathRef File) const { std::lock_guard Lock(Mutex); Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -381,10 +381,13 @@ void test() { Bar().^ } )cpp"); EXPECT_THAT(Results.Completions, - HasSubsequence(AllOf(Qualifier(""), Named("bar")), - AllOf(Qualifier("Foo::"), Named("foo")))); + Contains(AllOf(Qualifier(""), Named("bar")))); + // Hidden members are not shown. EXPECT_THAT(Results.Completions, - Not(Contains(AllOf(Qualifier(""), Named("foo"))))); // private + Not(Contains(AllOf(Qualifier("Foo::"), Named("foo"))))); + // Private members are not shown. + EXPECT_THAT(Results.Completions, + Not(Contains(AllOf(Qualifier(""), Named("foo"))))); } TEST(CompletionTest, InjectedTypename) {