[clang-tools-extra] 606ba8a - [clangd] Handle more than two conflicting semantic tokens in resolveConflict()
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 16 09:53:21 PDT 2022
Author: Nathan Ridge
Date: 2022-03-16T12:53:04-04:00
New Revision: 606ba8a68f79b8324c3ce018e7fa0173ce698526
URL: https://github.com/llvm/llvm-project/commit/606ba8a68f79b8324c3ce018e7fa0173ce698526
DIFF: https://github.com/llvm/llvm-project/commit/606ba8a68f79b8324c3ce018e7fa0173ce698526.diff
LOG: [clangd] Handle more than two conflicting semantic tokens in resolveConflict()
Fixes https://github.com/clangd/clangd/issues/1057
Differential Revision: https://reviews.llvm.org/D121775
Added:
Modified:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 492763cd99231..862cfc8edf0aa 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -313,21 +313,26 @@ unsigned evaluateHighlightPriority(const HighlightingToken &Tok) {
//
// In particular, heuristically resolved dependent names get their heuristic
// kind, plus the dependent modifier.
+llvm::Optional<HighlightingToken> resolveConflict(const HighlightingToken &A,
+ const HighlightingToken &B) {
+ unsigned Priority1 = evaluateHighlightPriority(A);
+ unsigned Priority2 = evaluateHighlightPriority(B);
+ if (Priority1 == Priority2 && A.Kind != B.Kind)
+ return llvm::None;
+ auto Result = Priority1 > Priority2 ? A : B;
+ Result.Modifiers = A.Modifiers | B.Modifiers;
+ return Result;
+}
llvm::Optional<HighlightingToken>
resolveConflict(ArrayRef<HighlightingToken> Tokens) {
if (Tokens.size() == 1)
return Tokens[0];
- if (Tokens.size() != 2)
- return llvm::None;
-
- unsigned Priority1 = evaluateHighlightPriority(Tokens[0]);
- unsigned Priority2 = evaluateHighlightPriority(Tokens[1]);
- if (Priority1 == Priority2 && Tokens[0].Kind != Tokens[1].Kind)
- return llvm::None;
- auto Result = Priority1 > Priority2 ? Tokens[0] : Tokens[1];
- Result.Modifiers = Tokens[0].Modifiers | Tokens[1].Modifiers;
- return Result;
+ assert(Tokens.size() >= 2);
+ Optional<HighlightingToken> Winner = resolveConflict(Tokens[0], Tokens[1]);
+ for (size_t I = 2; Winner && I < Tokens.size(); ++I)
+ Winner = resolveConflict(*Winner, Tokens[I]);
+ return Winner;
}
/// Consumes source locations and maps them to text ranges for highlightings.
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index a4e901d140999..210bc7736cdd0 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -615,7 +615,14 @@ sizeof...($TemplateParameter[[Elements]]);
void $Method_decl[[bar1]]() {
$Class[[Foo]]<$TemplateParameter[[U]]>().$Field_dependentName[[Waldo]];
}
+
+ void $Method_decl[[Overload]]();
+ void $Method_decl_readonly[[Overload]]() const;
};
+ template <typename $TemplateParameter_decl[[T]]>
+ void $Function_decl[[baz]]($Class[[Foo]]<$TemplateParameter[[T]]> $Parameter_decl[[o]]) {
+ $Parameter[[o]].$Method_readonly_dependentName[[Overload]]();
+ }
)cpp",
// Concepts
R"cpp(
More information about the cfe-commits
mailing list