ArcsinX updated this revision to Diff 328222. ArcsinX added a comment. Call `FileIndex::updateMain()` with an absolute file path in tests to avoid test failures in debug mode.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97535/new/ https://reviews.llvm.org/D97535 Files: clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/FileIndex.cpp clang-tools-extra/clangd/index/MemIndex.cpp clang-tools-extra/clangd/index/dex/Dex.cpp clang-tools-extra/clangd/test/memory_tree.test clang-tools-extra/clangd/unittests/DexTests.cpp clang-tools-extra/clangd/unittests/FileIndexTests.cpp clang-tools-extra/clangd/unittests/IndexTests.cpp
Index: clang-tools-extra/clangd/unittests/IndexTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/IndexTests.cpp +++ clang-tools-extra/clangd/unittests/IndexTests.cpp @@ -229,7 +229,7 @@ RefSlab Refs; auto Size = Symbols.bytes() + Refs.bytes(); auto Data = std::make_pair(std::move(Symbols), std::move(Refs)); - llvm::StringSet<> Files = {testPath("foo.cc"), testPath("bar.cc")}; + llvm::StringSet<> Files = {"unittest:///foo.cc", "unittest:///bar.cc"}; MemIndex I(std::move(Data.first), std::move(Data.second), RelationSlab(), std::move(Files), IndexContents::All, std::move(Data), Size); auto ContainsFile = I.indexedFiles(); @@ -506,7 +506,7 @@ RefSlab DynRefs; auto DynSize = DynSymbols.bytes() + DynRefs.bytes(); auto DynData = std::make_pair(std::move(DynSymbols), std::move(DynRefs)); - llvm::StringSet<> DynFiles = {testPath("foo.cc")}; + llvm::StringSet<> DynFiles = {"unittest:///foo.cc"}; MemIndex DynIndex(std::move(DynData.first), std::move(DynData.second), RelationSlab(), std::move(DynFiles), IndexContents::Symbols, std::move(DynData), DynSize); @@ -514,7 +514,7 @@ RefSlab StaticRefs; auto StaticData = std::make_pair(std::move(StaticSymbols), std::move(StaticRefs)); - llvm::StringSet<> StaticFiles = {testPath("foo.cc"), testPath("bar.cc")}; + llvm::StringSet<> StaticFiles = {"unittest:///foo.cc", "unittest:///bar.cc"}; MemIndex StaticIndex( std::move(StaticData.first), std::move(StaticData.second), RelationSlab(), std::move(StaticFiles), IndexContents::References, std::move(StaticData), Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -352,14 +352,14 @@ Test.Code = std::string(MainCode.code()); Test.Filename = "test.cc"; auto AST = Test.build(); - Index.updateMain(Test.Filename, AST); + Index.updateMain(testPath(Test.Filename), AST); // Add test2.cc TestTU Test2; Test2.HeaderCode = HeaderCode; Test2.Code = std::string(MainCode.code()); Test2.Filename = "test2.cc"; AST = Test2.build(); - Index.updateMain(Test2.Filename, AST); + Index.updateMain(testPath(Test2.Filename), AST); EXPECT_THAT(getRefs(Index, Foo.ID), RefsAre({AllOf(RefRange(MainCode.range("foo")), @@ -387,7 +387,7 @@ Test.Code = std::string(MainCode.code()); Test.Filename = "test.cc"; auto AST = Test.build(); - Index.updateMain(Test.Filename, AST); + Index.updateMain(testPath(Test.Filename), AST); auto HeaderMacro = findSymbol(Test.headerSymbols(), "HEADER_MACRO"); EXPECT_THAT(getRefs(Index, HeaderMacro.ID), Index: clang-tools-extra/clangd/unittests/DexTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/DexTests.cpp +++ clang-tools-extra/clangd/unittests/DexTests.cpp @@ -737,7 +737,7 @@ RefSlab Refs; auto Size = Symbols.bytes() + Refs.bytes(); auto Data = std::make_pair(std::move(Symbols), std::move(Refs)); - llvm::StringSet<> Files = {testPath("foo.cc"), testPath("bar.cc")}; + llvm::StringSet<> Files = {"unittest:///foo.cc", "unittest:///bar.cc"}; Dex I(std::move(Data.first), std::move(Data.second), RelationSlab(), std::move(Files), IndexContents::All, std::move(Data), Size); auto ContainsFile = I.indexedFiles(); Index: clang-tools-extra/clangd/test/memory_tree.test =================================================================== --- clang-tools-extra/clangd/test/memory_tree.test +++ clang-tools-extra/clangd/test/memory_tree.test @@ -23,7 +23,9 @@ # CHECK-NEXT: "_total": {{[0-9]+}} # CHECK-NEXT: }, # CHECK-NEXT: "slabs": { -# CHECK-NEXT: "{{.*}}main.cpp": { +# CHECK-NEXT: "_self": {{[0-9]+}}, +# CHECK-NEXT: "_total": {{[0-9]+}}, +# CHECK-NEXT: "test:///main.cpp": { # CHECK-NEXT: "_self": {{[0-9]+}}, # CHECK-NEXT: "_total": {{[0-9]+}}, # CHECK-NEXT: "references": { @@ -38,9 +40,7 @@ # CHECK-NEXT: "_self": {{[0-9]+}}, # CHECK-NEXT: "_total": {{[0-9]+}} # CHECK-NEXT: } -# CHECK-NEXT: }, -# CHECK-NEXT: "_self": {{[0-9]+}}, -# CHECK-NEXT: "_total": {{[0-9]+}} +# CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: }, # CHECK-NEXT: "preamble": { Index: clang-tools-extra/clangd/index/dex/Dex.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/Dex.cpp +++ clang-tools-extra/clangd/index/dex/Dex.cpp @@ -316,14 +316,7 @@ llvm::unique_function<IndexContents(llvm::StringRef) const> Dex::indexedFiles() const { return [this](llvm::StringRef FileURI) { - if (Files.empty()) - return IndexContents::None; - auto Path = URI::resolve(FileURI, Files.begin()->first()); - if (!Path) { - vlog("Failed to resolve the URI {0} : {1}", FileURI, Path.takeError()); - return IndexContents::None; - } - return Files.contains(*Path) ? IdxContents : IndexContents::None; + return Files.contains(FileURI) ? IdxContents : IndexContents::None; }; } Index: clang-tools-extra/clangd/index/MemIndex.cpp =================================================================== --- clang-tools-extra/clangd/index/MemIndex.cpp +++ clang-tools-extra/clangd/index/MemIndex.cpp @@ -112,14 +112,7 @@ llvm::unique_function<IndexContents(llvm::StringRef) const> MemIndex::indexedFiles() const { return [this](llvm::StringRef FileURI) { - if (Files.empty()) - return IndexContents::None; - auto Path = URI::resolve(FileURI, Files.begin()->first()); - if (!Path) { - vlog("Failed to resolve the URI {0} : {1}", FileURI, Path.takeError()); - return IndexContents::None; - } - return Files.contains(*Path) ? IdxContents : IndexContents::None; + return Files.contains(FileURI) ? IdxContents : IndexContents::None; }; } Index: clang-tools-extra/clangd/index/FileIndex.cpp =================================================================== --- clang-tools-extra/clangd/index/FileIndex.cpp +++ clang-tools-extra/clangd/index/FileIndex.cpp @@ -463,7 +463,8 @@ void FileIndex::updateMain(PathRef Path, ParsedAST &AST) { auto Contents = indexMainDecls(AST); MainFileSymbols.update( - Path, std::make_unique<SymbolSlab>(std::move(std::get<0>(Contents))), + URI::create(Path).toString(), + std::make_unique<SymbolSlab>(std::move(std::get<0>(Contents))), std::make_unique<RefSlab>(std::move(std::get<1>(Contents))), std::make_unique<RelationSlab>(std::move(std::get<2>(Contents))), /*CountReferences=*/true); Index: clang-tools-extra/clangd/index/Background.cpp =================================================================== --- clang-tools-extra/clangd/index/Background.cpp +++ clang-tools-extra/clangd/index/Background.cpp @@ -243,7 +243,7 @@ // this thread sees the older version but finishes later. This should be // rare in practice. IndexedSymbols.update( - Path, std::make_unique<SymbolSlab>(std::move(*IF->Symbols)), + Uri, std::make_unique<SymbolSlab>(std::move(*IF->Symbols)), std::make_unique<RefSlab>(std::move(*IF->Refs)), std::make_unique<RelationSlab>(std::move(*IF->Relations)), Path == MainFile); @@ -390,8 +390,9 @@ SV.HadErrors = LS.HadErrors; ++LoadedShards; - IndexedSymbols.update(LS.AbsolutePath, std::move(SS), std::move(RS), - std::move(RelS), LS.CountReferences); + IndexedSymbols.update(URI::create(LS.AbsolutePath).toString(), + std::move(SS), std::move(RS), std::move(RelS), + LS.CountReferences); } } Rebuilder.loadedShard(LoadedShards);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits