Skip to content
Permalink
Browse files

[clangd] Added highlighting for structured bindings.

Summary: Structured bindings are in a BindingDecl. The decl the declRefExpr points to are the BindingDecls. So this adds an additional if statement in the addToken function to highlight them.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66738

llvm-svn: 370473
  • Loading branch information
jvikstrom committed Aug 30, 2019
1 parent 4e71702 commit 268f45bfb8f79a90e5a0514ee7655075b26d547c
@@ -233,6 +233,10 @@ class HighlightingTokenCollector
: HighlightingKind::Variable);
return;
}
if (isa<BindingDecl>(D)) {
addToken(Loc, HighlightingKind::Variable);
return;
}
if (isa<FunctionDecl>(D)) {
addToken(Loc, HighlightingKind::Function);
return;
@@ -436,6 +436,21 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
assert($Variable[[x]] != $Variable[[y]]);
assert($Variable[[x]] != $Function[[f]]());
}
)cpp",
R"cpp(
struct $Class[[S]] {
$Primitive[[float]] $Field[[Value]];
$Class[[S]] *$Field[[Next]];
};
$Class[[S]] $Variable[[Global]][2] = {$Class[[S]](), $Class[[S]]()};
$Primitive[[void]] $Function[[f]]($Class[[S]] $Parameter[[P]]) {
$Primitive[[int]] $LocalVariable[[A]][2] = {1,2};
auto [$Variable[[B1]], $Variable[[B2]]] = $LocalVariable[[A]];
auto [$Variable[[G1]], $Variable[[G2]]] = $Variable[[Global]];
$Class[[auto]] [$Variable[[P1]], $Variable[[P2]]] = $Parameter[[P]];
// Highlights references to BindingDecls.
$Variable[[B1]]++;
}
)cpp"};
for (const auto &TestCase : TestCases) {
checkHighlightings(TestCase);

0 comments on commit 268f45b

Please sign in to comment.
You can’t perform that action at this time.