Skip to content

Commit

Permalink
[clangd] Add semantic token for labels
Browse files Browse the repository at this point in the history
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D143260
  • Loading branch information
ckandeler committed Jun 7, 2023
1 parent d57ed84 commit e72baa7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang-tools-extra/clangd/SemanticHighlighting.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/SemanticHighlighting.h
Expand Up @@ -52,6 +52,7 @@ enum class HighlightingKind {
Modifier,
Operator,
Bracket,
Label,

// This one is different from the other kinds as it's a line style
// rather than a token style.
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Expand Up @@ -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]] {
Expand Down

0 comments on commit e72baa7

Please sign in to comment.