forked from OSchip/llvm-project
[clangd] Added highlighting to enum constants.
Summary: VSCode does not have a scope for enum constants. So they were placed under "constant.other.enum" as that seems to be the most correct scope for enum constants. However, this makes theia color them blue (the same color it uses for keywords). Reviewers: hokein, sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64624 llvm-svn: 366045
This commit is contained in:
parent
6bd02a442c
commit
d02f17daed
|
@ -119,6 +119,10 @@ private:
|
|||
addToken(Loc, HighlightingKind::Enum);
|
||||
return;
|
||||
}
|
||||
if (isa<EnumConstantDecl>(D)) {
|
||||
addToken(Loc, HighlightingKind::EnumConstant);
|
||||
return;
|
||||
}
|
||||
if (isa<VarDecl>(D)) {
|
||||
addToken(Loc, HighlightingKind::Variable);
|
||||
return;
|
||||
|
@ -249,6 +253,8 @@ llvm::StringRef toTextMateScope(HighlightingKind Kind) {
|
|||
return "entity.name.type.class.cpp";
|
||||
case HighlightingKind::Enum:
|
||||
return "entity.name.type.enum.cpp";
|
||||
case HighlightingKind::EnumConstant:
|
||||
return "variable.other.enummember.cpp";
|
||||
case HighlightingKind::Namespace:
|
||||
return "entity.name.namespace.cpp";
|
||||
case HighlightingKind::NumKinds:
|
||||
|
|
|
@ -28,6 +28,7 @@ enum class HighlightingKind {
|
|||
Function,
|
||||
Class,
|
||||
Enum,
|
||||
EnumConstant,
|
||||
Namespace,
|
||||
|
||||
NumKinds,
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
# CHECK-NEXT: "entity.name.type.enum.cpp"
|
||||
# CHECK-NEXT: ],
|
||||
# CHECK-NEXT: [
|
||||
# CHECK-NEXT: "variable.other.enummember.cpp"
|
||||
# CHECK-NEXT: ],
|
||||
# CHECK-NEXT: [
|
||||
# CHECK-NEXT: "entity.name.namespace.cpp"
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK-NEXT: ]
|
||||
|
|
|
@ -37,7 +37,8 @@ void checkHighlightings(llvm::StringRef Code) {
|
|||
{HighlightingKind::Function, "Function"},
|
||||
{HighlightingKind::Class, "Class"},
|
||||
{HighlightingKind::Enum, "Enum"},
|
||||
{HighlightingKind::Namespace, "Namespace"}};
|
||||
{HighlightingKind::Namespace, "Namespace"},
|
||||
{HighlightingKind::EnumConstant, "EnumConstant"}};
|
||||
std::vector<HighlightingToken> ExpectedTokens;
|
||||
for (const auto &KindString : KindToString) {
|
||||
std::vector<HighlightingToken> Toks = makeHighlightingTokens(
|
||||
|
@ -103,12 +104,19 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
|
|||
}
|
||||
)cpp",
|
||||
R"cpp(
|
||||
enum class $Enum[[E]] {};
|
||||
enum $Enum[[EE]] {};
|
||||
enum class $Enum[[E]] {
|
||||
$EnumConstant[[A]],
|
||||
$EnumConstant[[B]],
|
||||
};
|
||||
enum $Enum[[EE]] {
|
||||
$EnumConstant[[Hi]],
|
||||
};
|
||||
struct $Class[[A]] {
|
||||
$Enum[[E]] EEE;
|
||||
$Enum[[EE]] EEEE;
|
||||
};
|
||||
int $Variable[[I]] = $EnumConstant[[Hi]];
|
||||
$Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
|
||||
)cpp",
|
||||
R"cpp(
|
||||
namespace $Namespace[[abc]] {
|
||||
|
@ -118,7 +126,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
|
|||
namespace $Namespace[[cde]] {
|
||||
struct $Class[[A]] {
|
||||
enum class $Enum[[B]] {
|
||||
Hi,
|
||||
$EnumConstant[[Hi]],
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -129,7 +137,7 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
|
|||
$Namespace[[abc]]::$Namespace[[bcd]]::$Namespace[[cde]];
|
||||
$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[AA]];
|
||||
$Namespace[[vwz]]::$Class[[A]]::$Enum[[B]] $Variable[[AAA]] =
|
||||
$Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::Hi;
|
||||
$Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::$EnumConstant[[Hi]];
|
||||
::$Namespace[[vwz]]::$Class[[A]] $Variable[[B]];
|
||||
::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[BB]];
|
||||
)cpp"};
|
||||
|
|
Loading…
Reference in New Issue