[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
This commit is contained in:
parent
3a6aaa4391
commit
aae7553b34
|
@ -93,6 +93,12 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VisitTypedefNameDecl(TypedefNameDecl *TD) {
|
||||||
|
if(const auto *TSI = TD->getTypeSourceInfo())
|
||||||
|
addTypeLoc(TD->getLocation(), TSI->getTypeLoc());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool VisitTypeLoc(TypeLoc &TL) {
|
bool VisitTypeLoc(TypeLoc &TL) {
|
||||||
// This check is for not getting two entries when there are anonymous
|
// This check is for not getting two entries when there are anonymous
|
||||||
// structs. It also makes us not highlight certain namespace qualifiers
|
// structs. It also makes us not highlight certain namespace qualifiers
|
||||||
|
@ -101,9 +107,7 @@ public:
|
||||||
if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
|
if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (const Type *TP = TL.getTypePtr())
|
addTypeLoc(TL.getBeginLoc(), TL);
|
||||||
if (const TagDecl *TD = TP->getAsTagDecl())
|
|
||||||
addToken(TL.getBeginLoc(), TD);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +122,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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) {
|
void addToken(SourceLocation Loc, const NamedDecl *D) {
|
||||||
if (D->getDeclName().isIdentifier() && D->getName().empty())
|
if (D->getDeclName().isIdentifier() && D->getName().empty())
|
||||||
// Don't add symbols that don't have any length.
|
// Don't add symbols that don't have any length.
|
||||||
|
|
|
@ -90,7 +90,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
|
||||||
typename T::A* $Field[[D]];
|
typename T::A* $Field[[D]];
|
||||||
};
|
};
|
||||||
$Namespace[[abc]]::$Class[[A]]<int> $Variable[[AA]];
|
$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]] {
|
struct $Class[[B]] {
|
||||||
$Class[[B]]();
|
$Class[[B]]();
|
||||||
~$Class[[B]]();
|
~$Class[[B]]();
|
||||||
|
@ -173,6 +173,19 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
|
||||||
}
|
}
|
||||||
int $Variable[[B]];
|
int $Variable[[B]];
|
||||||
$Class[[AA]] $Variable[[A]]{$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"};
|
)cpp"};
|
||||||
for (const auto &TestCase : TestCases) {
|
for (const auto &TestCase : TestCases) {
|
||||||
checkHighlightings(TestCase);
|
checkHighlightings(TestCase);
|
||||||
|
|
Loading…
Reference in New Issue