This revision was automatically updated to reflect the committed changes. Closed by commit rG46c921003c2c: [clangd] Always retrieve ProjectInfo from Base in OverlayCDB (authored by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83934/new/ https://reviews.llvm.org/D83934 Files: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp clang-tools-extra/clangd/GlobalCompilationDatabase.h clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp @@ -313,9 +313,22 @@ llvm::sys::path::append(File, "blabla", "..", "a.cc"); EXPECT_TRUE(DB.getCompileCommand(File)); - EXPECT_TRUE(DB.getProjectInfo(File)); + EXPECT_FALSE(DB.getProjectInfo(File)); } +TEST_F(OverlayCDBTest, GetProjectInfo) { + OverlayCDB DB(Base.get()); + Path File = testPath("foo.cc"); + Path Header = testPath("foo.h"); + + EXPECT_EQ(DB.getProjectInfo(File)->SourceRoot, testRoot()); + EXPECT_EQ(DB.getProjectInfo(Header)->SourceRoot, testRoot()); + + // Shouldn't change after an override. + DB.setCompileCommand(File, tooling::CompileCommand()); + EXPECT_EQ(DB.getProjectInfo(File)->SourceRoot, testRoot()); + EXPECT_EQ(DB.getProjectInfo(Header)->SourceRoot, testRoot()); +} } // namespace } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/GlobalCompilationDatabase.h =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.h +++ clang-tools-extra/clangd/GlobalCompilationDatabase.h @@ -119,7 +119,6 @@ getQueryDriverDatabase(llvm::ArrayRef<std::string> QueryDriverGlobs, std::unique_ptr<GlobalCompilationDatabase> Base); - /// Wraps another compilation database, and supports overriding the commands /// using an in-memory mapping. class OverlayCDB : public GlobalCompilationDatabase { @@ -134,6 +133,8 @@ llvm::Optional<tooling::CompileCommand> getCompileCommand(PathRef File) const override; tooling::CompileCommand getFallbackCommand(PathRef File) const override; + /// Project info is gathered purely from the inner compilation database to + /// ensure consistency. llvm::Optional<ProjectInfo> getProjectInfo(PathRef File) const override; /// Sets or clears the compilation command for a particular file. Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -298,15 +298,11 @@ } llvm::Optional<ProjectInfo> OverlayCDB::getProjectInfo(PathRef File) const { - { - std::lock_guard<std::mutex> Lock(Mutex); - auto It = Commands.find(removeDots(File)); - if (It != Commands.end()) - return ProjectInfo{}; - } + // It wouldn't make much sense to treat files with overridden commands + // specially when we can't do the same for the (unknown) local headers they + // include or changing behavior mid-air after receiving an override. if (Base) return Base->getProjectInfo(File); - return llvm::None; } } // namespace clangd
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp @@ -313,9 +313,22 @@ llvm::sys::path::append(File, "blabla", "..", "a.cc"); EXPECT_TRUE(DB.getCompileCommand(File)); - EXPECT_TRUE(DB.getProjectInfo(File)); + EXPECT_FALSE(DB.getProjectInfo(File)); } +TEST_F(OverlayCDBTest, GetProjectInfo) { + OverlayCDB DB(Base.get()); + Path File = testPath("foo.cc"); + Path Header = testPath("foo.h"); + + EXPECT_EQ(DB.getProjectInfo(File)->SourceRoot, testRoot()); + EXPECT_EQ(DB.getProjectInfo(Header)->SourceRoot, testRoot()); + + // Shouldn't change after an override. + DB.setCompileCommand(File, tooling::CompileCommand()); + EXPECT_EQ(DB.getProjectInfo(File)->SourceRoot, testRoot()); + EXPECT_EQ(DB.getProjectInfo(Header)->SourceRoot, testRoot()); +} } // namespace } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/GlobalCompilationDatabase.h =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.h +++ clang-tools-extra/clangd/GlobalCompilationDatabase.h @@ -119,7 +119,6 @@ getQueryDriverDatabase(llvm::ArrayRef<std::string> QueryDriverGlobs, std::unique_ptr<GlobalCompilationDatabase> Base); - /// Wraps another compilation database, and supports overriding the commands /// using an in-memory mapping. class OverlayCDB : public GlobalCompilationDatabase { @@ -134,6 +133,8 @@ llvm::Optional<tooling::CompileCommand> getCompileCommand(PathRef File) const override; tooling::CompileCommand getFallbackCommand(PathRef File) const override; + /// Project info is gathered purely from the inner compilation database to + /// ensure consistency. llvm::Optional<ProjectInfo> getProjectInfo(PathRef File) const override; /// Sets or clears the compilation command for a particular file. Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp =================================================================== --- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -298,15 +298,11 @@ } llvm::Optional<ProjectInfo> OverlayCDB::getProjectInfo(PathRef File) const { - { - std::lock_guard<std::mutex> Lock(Mutex); - auto It = Commands.find(removeDots(File)); - if (It != Commands.end()) - return ProjectInfo{}; - } + // It wouldn't make much sense to treat files with overridden commands + // specially when we can't do the same for the (unknown) local headers they + // include or changing behavior mid-air after receiving an override. if (Base) return Base->getProjectInfo(File); - return llvm::None; } } // namespace clangd
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits