[PATCH] D121775: [clangd] Handle more than two conflicting semantic tokens in resolveConflict()
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 16 09:53:27 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG606ba8a68f79: [clangd] Handle more than two conflicting semantic tokens in resolveConflict() (authored by nridge).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121775/new/
https://reviews.llvm.org/D121775
Files:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -615,7 +615,14 @@
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(
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -313,21 +313,26 @@
//
// 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121775.415883.patch
Type: text/x-patch
Size: 2534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220316/1d3de31c/attachment.bin>
More information about the cfe-commits
mailing list