[clang-tools-extra] e72baa7 - [clangd] Add semantic token for labels
Christian Kandeler via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 7 03:28:18 PDT 2023
Author: Christian Kandeler
Date: 2023-06-07T12:28:06+02:00
New Revision: e72baa76b91fbcb2b16747cb7d2088723478a754
URL: https://github.com/llvm/llvm-project/commit/e72baa76b91fbcb2b16747cb7d2088723478a754
DIFF: https://github.com/llvm/llvm-project/commit/e72baa76b91fbcb2b16747cb7d2088723478a754.diff
LOG: [clangd] Add semantic token for labels
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D143260
Added:
Modified:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
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 ec37476cf94ea..6a835f31f064b 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -166,6 +166,8 @@ std::optional<HighlightingKind> kindForDecl(const NamedDecl *D,
return HighlightingKind::TemplateParameter;
if (isa<ConceptDecl>(D))
return HighlightingKind::Concept;
+ if (isa<LabelDecl>(D))
+ return HighlightingKind::Label;
if (const auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(D)) {
auto Targets = Resolver->resolveUsingValueDecl(UUVD);
if (!Targets.empty() && Targets[0] != UUVD) {
@@ -1271,6 +1273,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, HighlightingKind K) {
return OS << "Operator";
case HighlightingKind::Bracket:
return OS << "Bracket";
+ case HighlightingKind::Label:
+ return OS << "Label";
case HighlightingKind::InactiveCode:
return OS << "InactiveCode";
}
@@ -1470,6 +1474,8 @@ llvm::StringRef toSemanticTokenType(HighlightingKind Kind) {
return "operator";
case HighlightingKind::Bracket:
return "bracket";
+ case HighlightingKind::Label:
+ return "label";
case HighlightingKind::InactiveCode:
return "comment";
}
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h
index c9db598ff08c9..59d742b83ee52 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.h
+++ b/clang-tools-extra/clangd/SemanticHighlighting.h
@@ -52,6 +52,7 @@ enum class HighlightingKind {
Modifier,
Operator,
Bracket,
+ Label,
// This one is
diff erent from the other kinds as it's a line style
// rather than a token style.
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 9c6e5246f5c37..ff052e6be9549 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1028,6 +1028,16 @@ sizeof...($TemplateParameter[[Elements]]);
template $Bracket[[<]]$Concept[[C2]]$Bracket[[<]]int$Bracket[[>]] $TemplateParameter_def[[A]]$Bracket[[>]]
class $Class_def[[B]] {};
)cpp",
+ // Labels
+ R"cpp(
+ bool $Function_def[[funcWithGoto]](bool $Parameter_def[[b]]) {
+ if ($Parameter[[b]])
+ goto $Label[[return_true]];
+ return false;
+ $Label_decl[[return_true]]:
+ return true;
+ }
+ )cpp",
// no crash
R"cpp(
struct $Class_def[[Foo]] {
More information about the cfe-commits
mailing list