diff options
| author | Johan Vikstrom <jvikstrom@google.com> | 2019-08-30 14:07:05 +0000 |
|---|---|---|
| committer | Johan Vikstrom <jvikstrom@google.com> | 2019-08-30 14:07:05 +0000 |
| commit | 268f45bfb8f79a90e5a0514ee7655075b26d547c (patch) | |
| tree | 9fcae16830dede2bd49a3f64fb62986850959abe | |
| parent | 4e71702cd4ab2c77aaa753770e99526085e5e6eb (diff) | |
| download | bcm5719-llvm-268f45bfb8f79a90e5a0514ee7655075b26d547c.tar.gz bcm5719-llvm-268f45bfb8f79a90e5a0514ee7655075b26d547c.zip | |
[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
| -rw-r--r-- | clang-tools-extra/clangd/SemanticHighlighting.cpp | 4 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp | 15 |
2 files changed, 19 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 1c632bc250d..e71c0a733a6 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -233,6 +233,10 @@ private: : HighlightingKind::Variable); return; } + if (isa<BindingDecl>(D)) { + addToken(Loc, HighlightingKind::Variable); + return; + } if (isa<FunctionDecl>(D)) { addToken(Loc, HighlightingKind::Function); return; diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index 32510b494e0..04828d0e741 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -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); |

