Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp =================================================================== --- clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp +++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp @@ -105,7 +105,17 @@ llvm::errs() << llvm::toString(std::move(Err)) << "\n"; } + // Deduplicate the result by key. + // FIXME(ioeric): we need a better way to merge symbols with the same key. For + // example, class forward-declarations can have the same key as the class + // definition, and we should merge them instead of ignoring one of them. We + // would also need to aggregate signals like usage count when they are added. + llvm::StringMap ReducedSymbols; Executor->get()->getToolResults()->forEachResult( - [](llvm::StringRef, llvm::StringRef Value) { llvm::outs() << Value; }); + [&ReducedSymbols](llvm::StringRef Key, llvm::StringRef Value) { + ReducedSymbols[Key] = Value; + }); + for (const auto &Sym : ReducedSymbols) + llvm::outs() << Sym.second; return 0; }