[PATCH] D150683: [clangd] Tweak "provides" hover card when symbols have the same name
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 17 11:25:51 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e66105a9260: [clangd] Tweak "provides" hover card when symbols have the same name (authored by sammccall).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150683/new/
https://reviews.llvm.org/D150683
Files:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ 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"};
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ 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()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150683.523124.patch
Type: text/x-patch
Size: 2618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230517/e65f8fc6/attachment.bin>
More information about the cfe-commits
mailing list