[clang-tools-extra] 57f9518 - [clangd] Highlight structured bindings at local scope as LocalVariable
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 7 00:23:27 PDT 2020
Author: Nathan Ridge
Date: 2020-08-07T03:23:10-04:00
New Revision: 57f9518bf032d773c35c86ec99983a47849fd322
URL: https://github.com/llvm/llvm-project/commit/57f9518bf032d773c35c86ec99983a47849fd322
DIFF: https://github.com/llvm/llvm-project/commit/57f9518bf032d773c35c86ec99983a47849fd322.diff
LOG: [clangd] Highlight structured bindings at local scope as LocalVariable
Differential Revision: https://reviews.llvm.org/D85500
Added:
Modified:
clang-tools-extra/clangd/SemanticHighlighting.cpp
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 4bedea457e5c..fb1ef1e326b4 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -90,8 +90,10 @@ llvm::Optional<HighlightingKind> kindForDecl(const NamedDecl *D) {
? HighlightingKind::StaticField
: VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
: HighlightingKind::Variable;
- if (isa<BindingDecl>(D))
- return HighlightingKind::Variable;
+ if (const auto *BD = dyn_cast<BindingDecl>(D))
+ return BD->getDeclContext()->isFunctionOrMethod()
+ ? HighlightingKind::LocalVariable
+ : HighlightingKind::Variable;
if (isa<FunctionDecl>(D))
return HighlightingKind::Function;
if (isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D) ||
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 1b90b21b2c58..f9c2e7433cc4 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -515,13 +515,14 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
$Class[[S]] *$Field[[Next]];
};
$Class[[S]] $Variable[[Global]][2] = {$Class[[S]](), $Class[[S]]()};
+ auto [$Variable[[G1]], $Variable[[G2]]] = $Variable[[Global]];
void $Function[[f]]($Class[[S]] $Parameter[[P]]) {
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]];
+ auto [$LocalVariable[[B1]], $LocalVariable[[B2]]] = $LocalVariable[[A]];
+ auto [$LocalVariable[[G1]], $LocalVariable[[G2]]] = $Variable[[Global]];
+ $Class[[auto]] [$LocalVariable[[P1]], $LocalVariable[[P2]]] = $Parameter[[P]];
// Highlights references to BindingDecls.
- $Variable[[B1]]++;
+ $LocalVariable[[B1]]++;
}
)cpp",
R"cpp(
More information about the cfe-commits
mailing list