[clangd] Set SymbolID for sema macros so that they can be merged with index macros.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51688
llvm-svn: 341534
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 7a83243..ee24cf7 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -385,18 +385,16 @@
Roles & static_cast<unsigned>(index::SymbolRole::Definition)))
return true;
- llvm::SmallString<128> USR;
- if (index::generateUSRForMacro(Name->getName(), MI->getDefinitionLoc(), SM,
- USR))
+ auto ID = getSymbolID(*Name, MI, SM);
+ if (!ID)
return true;
- SymbolID ID(USR);
// Only collect one instance in case there are multiple.
- if (Symbols.find(ID) != nullptr)
+ if (Symbols.find(*ID) != nullptr)
return true;
Symbol S;
- S.ID = std::move(ID);
+ S.ID = std::move(*ID);
S.Name = Name->getName();
S.IsIndexedForCodeCompletion = true;
S.SymInfo = index::getSymbolInfoForMacro(*MI);
@@ -445,11 +443,9 @@
if (Opts.CollectMacro) {
assert(PP);
for (const IdentifierInfo *II : ReferencedMacros) {
- llvm::SmallString<128> USR;
if (const auto *MI = PP->getMacroDefinition(II).getMacroInfo())
- if (!index::generateUSRForMacro(II->getName(), MI->getDefinitionLoc(),
- PP->getSourceManager(), USR))
- IncRef(SymbolID(USR));
+ if (auto ID = getSymbolID(*II, MI, PP->getSourceManager()))
+ IncRef(*ID);
}
}