diff options
author | Johan Vikstrom <jvikstrom@google.com> | 2019-07-16 13:23:12 +0000 |
---|---|---|
committer | Johan Vikstrom <jvikstrom@google.com> | 2019-07-16 13:23:12 +0000 |
commit | aae7553b3463558c2f7ad40de1b60b989fea0f05 (patch) | |
tree | 88c4c598883c165c836cd236c1647df170b2e5a3 | |
parent | 3a6aaa4391f058201d8cec737ab2e6903ef65892 (diff) | |
download | bcm5719-llvm-aae7553b3463558c2f7ad40de1b60b989fea0f05.tar.gz bcm5719-llvm-aae7553b3463558c2f7ad40de1b60b989fea0f05.zip |
[clangd] Added highlighting for the targets in typedefs and using.
Summary:
In `typedef int A` the `A` was not highlighted previously.
This patch gives `A` the same kind of highlighting that the underlying type has (class/enum) (which in this example is no special highlighting because builtins are not handled yet)
Will add highlightings for built ins in another patch.
Reviewers: hokein, sammccall, ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64754
llvm-svn: 366207
-rw-r--r-- | clang-tools-extra/clangd/SemanticHighlighting.cpp | 16 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp | 15 |
2 files changed, 27 insertions, 4 deletions
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index d64472d8fdb..b6b1c8d8a2c 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -93,6 +93,12 @@ public: return true; } + bool VisitTypedefNameDecl(TypedefNameDecl *TD) { + if(const auto *TSI = TD->getTypeSourceInfo()) + addTypeLoc(TD->getLocation(), TSI->getTypeLoc()); + return true; + } + bool VisitTypeLoc(TypeLoc &TL) { // This check is for not getting two entries when there are anonymous // structs. It also makes us not highlight certain namespace qualifiers @@ -101,9 +107,7 @@ public: if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated) return true; - if (const Type *TP = TL.getTypePtr()) - if (const TagDecl *TD = TP->getAsTagDecl()) - addToken(TL.getBeginLoc(), TD); + addTypeLoc(TL.getBeginLoc(), TL); return true; } @@ -118,6 +122,12 @@ public: } private: + void addTypeLoc(SourceLocation Loc, const TypeLoc &TL) { + if (const Type *TP = TL.getTypePtr()) + if (const TagDecl *TD = TP->getAsTagDecl()) + addToken(Loc, TD); + } + void addToken(SourceLocation Loc, const NamedDecl *D) { if (D->getDeclName().isIdentifier() && D->getName().empty()) // Don't add symbols that don't have any length. diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index 3a1b1c3e705..f69e336253c 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -90,7 +90,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) { typename T::A* $Field[[D]]; }; $Namespace[[abc]]::$Class[[A]]<int> $Variable[[AA]]; - typedef $Namespace[[abc]]::$Class[[A]]<int> AAA; + typedef $Namespace[[abc]]::$Class[[A]]<int> $Class[[AAA]]; struct $Class[[B]] { $Class[[B]](); ~$Class[[B]](); @@ -173,6 +173,19 @@ TEST(SemanticHighlighting, GetsCorrectTokens) { } int $Variable[[B]]; $Class[[AA]] $Variable[[A]]{$Variable[[B]]}; + )cpp", + R"cpp( + namespace $Namespace[[a]] { + struct $Class[[A]] {}; + } + typedef $Namespace[[a]]::$Class[[A]] $Class[[B]]; + using $Class[[BB]] = $Namespace[[a]]::$Class[[A]]; + enum class $Enum[[E]] {}; + typedef $Enum[[E]] $Enum[[C]]; + typedef $Enum[[C]] $Enum[[CC]]; + using $Enum[[CD]] = $Enum[[CC]]; + $Enum[[CC]] $Function[[f]]($Class[[B]]); + $Enum[[CD]] $Function[[f]]($Class[[BB]]); )cpp"}; for (const auto &TestCase : TestCases) { checkHighlightings(TestCase); |