diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -229,6 +229,21 @@ addToken(Loc, HighlightingKind::Variable); return; } + if (const auto *B = dyn_cast(D)) { + // If we can find the underlying decl and highlight that we should do it. + // So first try to find and highlight the underlying NamedDecl for the + // binding if one exist. + if (const auto *BB = B->getBinding()) + if (const auto *RD = BB->getReferencedDeclOfCallee()) + if (const auto *D = dyn_cast(RD)) { + addToken(Loc, D); + return; + } + // Could not find a more specific decl for this BindingDecl. So just + // highlight as a normal variable. + addToken(Loc, HighlightingKind::Variable); + return; + } if (isa(D)) { addToken(Loc, HighlightingKind::Function); return; diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -431,6 +431,23 @@ assert($Variable[[x]] != $Variable[[y]]); assert($Variable[[x]] != $Function[[f]]()); } + )cpp", + R"cpp( + struct $Class[[S]] { + $Primitive[[float]] $Field[[Member]]; + }; + $Class[[S]] $Function[[foo]](); + $Primitive[[void]] $Function[[f]]() { + $Primitive[[int]] $Variable[[A]][2] = {1,2}; + auto [$Variable[[B1]], $Variable[[B2]]] = $Variable[[A]]; + auto& [$Variable[[R1]], $Variable[[R2]]] = $Variable[[A]]; + $Class[[auto]] [$Field[[M1]]] = $Class[[S]](); + $Class[[auto]] [$Field[[F1]]] = $Function[[foo]](); + $Field[[M1]] += 12.2; + $Variable[[B1]] += 2; + $Class[[S]] $Variable[[SArr]][2] = {$Class[[S]](), $Class[[S]]()}; + auto [$Variable[[S1]], $Variable[[S2]]] = $Variable[[SArr]]; + } )cpp"}; for (const auto &TestCase : TestCases) { checkHighlightings(TestCase);