[PATCH] D143260: [clangd] Add semantic token for labels
Christian Kandeler via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 3 03:41:26 PST 2023
ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143260
Files:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
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
@@ -1025,6 +1025,16 @@
template $Bracket[[<]]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]] {
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -52,6 +52,7 @@
Modifier,
Operator,
Bracket,
+ Label,
// This one is different from the other kinds as it's a line style
// rather than a token style.
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -154,6 +154,8 @@
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()) {
@@ -1212,6 +1214,8 @@
return OS << "Operator";
case HighlightingKind::Bracket:
return OS << "Bracket";
+ case HighlightingKind::Label:
+ return OS << "Label";
case HighlightingKind::InactiveCode:
return OS << "InactiveCode";
}
@@ -1352,6 +1356,8 @@
return "operator";
case HighlightingKind::Bracket:
return "bracket";
+ case HighlightingKind::Label:
+ return "label";
case HighlightingKind::InactiveCode:
return "comment";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143260.494583.patch
Type: text/x-patch
Size: 2280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230203/cd736763/attachment.bin>
More information about the cfe-commits
mailing list