Index: clangd/index/Background.cpp =================================================================== --- clangd/index/Background.cpp +++ clangd/index/Background.cpp @@ -306,17 +306,20 @@ // Build and store new slabs for each updated file. for (const auto &I : *Index.Sources) { + // We already have the map from uris to absolutepaths in the cache, + // therefore traverse Index.Sources rather than Files to get rid of absolute + // path to uri conversion. std::string Path = URICache.resolve(I.first()); + auto FileIt = Files.find(Path); + if (FileIt == Files.end()) + continue; SymbolSlab::Builder Syms; RefSlab::Builder Refs; - auto FileIt = Files.find(Path); - if (FileIt != Files.end()) { - auto &F = *FileIt; - for (const auto *S : F.second.Symbols) - Syms.insert(*S); - for (const auto *R : F.second.Refs) - Refs.insert(RefToIDs[R], *R); - } + auto &F = *FileIt; + for (const auto *S : F.second.Symbols) + Syms.insert(*S); + for (const auto *R : F.second.Refs) + Refs.insert(RefToIDs[R], *R); auto SS = llvm::make_unique(std::move(Syms).build()); auto RS = llvm::make_unique(std::move(Refs).build()); auto IG = llvm::make_unique( Index: unittests/clangd/BackgroundIndexTests.cpp =================================================================== --- unittests/clangd/BackgroundIndexTests.cpp +++ unittests/clangd/BackgroundIndexTests.cpp @@ -351,8 +351,11 @@ EXPECT_EQ(CacheHits, 2U); // Check both A.cc and A.h loaded from cache. // Check if the new symbol has arrived. - auto ShardSource = MSS.loadShard(testPath("root/A.cc")); + ShardHeader = MSS.loadShard(testPath("root/A.h")); EXPECT_NE(ShardHeader, nullptr); + EXPECT_THAT(*ShardHeader->Symbols, Contains(Named("A_CCnew"))); + auto ShardSource = MSS.loadShard(testPath("root/A.cc")); + EXPECT_NE(ShardSource, nullptr); EXPECT_THAT(*ShardSource->Symbols, Contains(AllOf(Named("f_b"), Declared(), Defined()))); }