[clang-tools-extra] r366070 - [clangd] Fix duplicate highlighting tokens appearing in initializer lists.
Johan Vikstrom via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 15 08:08:27 PDT 2019
Author: jvikstrom
Date: Mon Jul 15 08:08:27 2019
New Revision: 366070
URL: http://llvm.org/viewvc/llvm-project?rev=366070&view=rev
Log:
[clangd] Fix duplicate highlighting tokens appearing in initializer lists.
Summary: The RecursiveASTVisitor sometimes visits exprs in initializer lists twice. Added deduplication to prevent duplicate highlighting tokens from appearing. Done by sorting and a linear search.
Reviewers: hokein, sammccall, ilya-biryukov
Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64634
Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=366070&r1=366069&r2=366070&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Mon Jul 15 08:08:27 2019
@@ -31,6 +31,14 @@ public:
std::vector<HighlightingToken> collectTokens() {
Tokens.clear();
TraverseAST(Ctx);
+ // Initializer lists can give duplicates of tokens, therefore all tokens
+ // must be deduplicated.
+ llvm::sort(Tokens,
+ [](const HighlightingToken &L, const HighlightingToken &R) {
+ return std::tie(L.R, L.Kind) < std::tie(R.R, R.Kind);
+ });
+ auto Last = std::unique(Tokens.begin(), Tokens.end());
+ Tokens.erase(Last, Tokens.end());
return Tokens;
}
Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=366070&r1=366069&r2=366070&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Mon Jul 15 08:08:27 2019
@@ -166,6 +166,13 @@ TEST(SemanticHighlighting, GetsCorrectTo
$Variable[[AA]].$Field[[E]].$Field[[C]];
$Class[[A]]::$Variable[[S]] = 90;
}
+ )cpp",
+ R"cpp(
+ struct $Class[[AA]] {
+ int $Field[[A]];
+ }
+ int $Variable[[B]];
+ $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
)cpp"};
for (const auto &TestCase : TestCases) {
checkHighlightings(TestCase);
More information about the cfe-commits
mailing list