diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -1268,6 +1268,9 @@ for (const auto &UsedSymbolDecl : UsedSymbols) HI.UsedSymbolNames.push_back(getSymbolName(UsedSymbolDecl)); llvm::sort(HI.UsedSymbolNames); + HI.UsedSymbolNames.erase( + std::unique(HI.UsedSymbolNames.begin(), HI.UsedSymbolNames.end()), + HI.UsedSymbolNames.end()); } } // namespace @@ -1529,16 +1532,11 @@ P.appendText("provides "); const std::vector<std::string>::size_type SymbolNamesLimit = 5; - auto Front = - llvm::ArrayRef(UsedSymbolNames) - .take_front(std::min(UsedSymbolNames.size(), SymbolNamesLimit)); - - for (const auto &Sym : Front) { - P.appendCode(Sym); - if (Sym != Front.back()) - P.appendText(", "); - } + auto Front = llvm::ArrayRef(UsedSymbolNames).take_front(SymbolNamesLimit); + llvm::interleave( + Front, [&](llvm::StringRef Sym) { P.appendCode(Sym); }, + [&] { P.appendText(", "); }); if (UsedSymbolNames.size() > Front.size()) { P.appendText(" and "); P.appendText(std::to_string(UsedSymbolNames.size() - Front.size())); diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -3052,6 +3052,7 @@ } Cases[] = {{R"cpp( #include ^"bar.h" int fstBar = bar1(); + int another= bar1(0); int sndBar = bar2(); Bar bar; int macroBar = BAR; @@ -3075,6 +3076,7 @@ #define BAR 5 int bar1(); int bar2(); + int bar1(double); class Bar {}; )cpp"); TU.AdditionalFiles["system/vector"] = guard(R"cpp( @@ -3487,11 +3489,11 @@ }, {[](HoverInfo &HI) { HI.Name = "foo.h"; - HI.UsedSymbolNames = {"Foo", "Bar", "Baz"}; + HI.UsedSymbolNames = {"Foo", "Bar", "Bar"}; }, R"(foo.h -provides Foo, Bar, Baz)"}, +provides Foo, Bar, Bar)"}, {[](HoverInfo &HI) { HI.Name = "foo.h"; HI.UsedSymbolNames = {"Foo", "Bar", "Baz", "Foobar", "Qux", "Quux"};