[clang-tools-extra] r370429 - [clangd] Add distinct highlightings for static fields and methods
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 20:37:24 PDT 2019
Author: nridge
Date: Thu Aug 29 20:37:24 2019
New Revision: 370429
URL: http://llvm.org/viewvc/llvm-project?rev=370429&view=rev
Log:
[clangd] Add distinct highlightings for static fields and methods
Reviewers: hokein, ilya-biryukov, jvikstrom
Reviewed By: hokein
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66828
Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.h
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=370429&r1=370428&r2=370429&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Thu Aug 29 20:37:24 2019
@@ -205,8 +205,9 @@ private:
addToken(Loc, HighlightingKind::Class);
return;
}
- if (isa<CXXMethodDecl>(D)) {
- addToken(Loc, HighlightingKind::Method);
+ if (auto *MD = dyn_cast<CXXMethodDecl>(D)) {
+ addToken(Loc, MD->isStatic() ? HighlightingKind::StaticMethod
+ : HighlightingKind::Method);
return;
}
if (isa<FieldDecl>(D)) {
@@ -226,8 +227,10 @@ private:
return;
}
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
- addToken(Loc, VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
- : HighlightingKind::Variable);
+ addToken(Loc, VD->isStaticDataMember()
+ ? HighlightingKind::StaticField
+ : VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
+ : HighlightingKind::Variable);
return;
}
if (isa<FunctionDecl>(D)) {
@@ -435,6 +438,8 @@ llvm::StringRef toTextMateScope(Highligh
return "entity.name.function.cpp";
case HighlightingKind::Method:
return "entity.name.function.method.cpp";
+ case HighlightingKind::StaticMethod:
+ return "entity.name.function.method.static.cpp";
case HighlightingKind::Variable:
return "variable.other.cpp";
case HighlightingKind::LocalVariable:
@@ -443,6 +448,8 @@ llvm::StringRef toTextMateScope(Highligh
return "variable.parameter.cpp";
case HighlightingKind::Field:
return "variable.other.field.cpp";
+ case HighlightingKind::StaticField:
+ return "variable.other.field.static.cpp";
case HighlightingKind::Class:
return "entity.name.type.class.cpp";
case HighlightingKind::Enum:
Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.h?rev=370429&r1=370428&r2=370429&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h Thu Aug 29 20:37:24 2019
@@ -29,7 +29,9 @@ enum class HighlightingKind {
Parameter,
Function,
Method,
+ StaticMethod,
Field,
+ StaticField,
Class,
Enum,
EnumConstant,
Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=370429&r1=370428&r2=370429&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test Thu Aug 29 20:37:24 2019
@@ -20,9 +20,15 @@
# CHECK-NEXT: "entity.name.function.method.cpp"
# CHECK-NEXT: ],
# CHECK-NEXT: [
+# CHECK-NEXT: "entity.name.function.method.static.cpp"
+# CHECK-NEXT: ],
+# CHECK-NEXT: [
# CHECK-NEXT: "variable.other.field.cpp"
# CHECK-NEXT: ],
# CHECK-NEXT: [
+# CHECK-NEXT: "variable.other.field.static.cpp"
+# CHECK-NEXT: ],
+# CHECK-NEXT: [
# CHECK-NEXT: "entity.name.type.class.cpp"
# CHECK-NEXT: ],
# CHECK-NEXT: [
@@ -49,7 +55,7 @@
# CHECK-NEXT: "lines": [
# CHECK-NEXT: {
# CHECK-NEXT: "line": 0,
-# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
+# CHECK-NEXT: "tokens": "AAAAAAADAA0AAAAEAAEAAA=="
# CHECK-NEXT: }
# CHECK-NEXT: ],
# CHECK-NEXT: "textDocument": {
@@ -64,11 +70,11 @@
# CHECK-NEXT: "lines": [
# CHECK-NEXT: {
# CHECK-NEXT: "line": 0,
-# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
+# CHECK-NEXT: "tokens": "AAAAAAADAA0AAAAEAAEAAA=="
# CHECK-NEXT: }
# CHECK-NEXT: {
# CHECK-NEXT: "line": 1,
-# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
+# CHECK-NEXT: "tokens": "AAAAAAADAA0AAAAEAAEAAA=="
# CHECK-NEXT: }
# CHECK-NEXT: ],
# CHECK-NEXT: "textDocument": {
@@ -83,7 +89,7 @@
# CHECK-NEXT: "lines": [
# CHECK-NEXT: {
# CHECK-NEXT: "line": 1,
-# CHECK-NEXT: "tokens": "AAAAAAADAAsAAAAEAAEAAA=="
+# CHECK-NEXT: "tokens": "AAAAAAADAA0AAAAEAAEAAA=="
# CHECK-NEXT: }
# CHECK-NEXT: ],
# CHECK-NEXT: "textDocument": {
Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=370429&r1=370428&r2=370429&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Thu Aug 29 20:37:24 2019
@@ -35,6 +35,7 @@ makeHighlightingTokens(llvm::ArrayRef<Ra
std::vector<HighlightingToken> getExpectedTokens(Annotations &Test) {
static const std::map<HighlightingKind, std::string> KindToString{
{HighlightingKind::Variable, "Variable"},
+ {HighlightingKind::LocalVariable, "LocalVariable"},
{HighlightingKind::Parameter, "Parameter"},
{HighlightingKind::Function, "Function"},
{HighlightingKind::Class, "Class"},
@@ -42,10 +43,11 @@ std::vector<HighlightingToken> getExpect
{HighlightingKind::Namespace, "Namespace"},
{HighlightingKind::EnumConstant, "EnumConstant"},
{HighlightingKind::Field, "Field"},
+ {HighlightingKind::StaticField, "StaticField"},
{HighlightingKind::Method, "Method"},
+ {HighlightingKind::StaticMethod, "StaticMethod"},
{HighlightingKind::TemplateParameter, "TemplateParameter"},
- {HighlightingKind::Primitive, "Primitive"},
- {HighlightingKind::LocalVariable, "LocalVariable"}};
+ {HighlightingKind::Primitive, "Primitive"}};
std::vector<HighlightingToken> ExpectedTokens;
for (const auto &KindString : KindToString) {
std::vector<HighlightingToken> Toks = makeHighlightingTokens(
@@ -200,13 +202,15 @@ TEST(SemanticHighlighting, GetsCorrectTo
struct $Class[[A]] {
$Primitive[[double]] $Field[[B]];
$Class[[D]] $Field[[E]];
- static $Primitive[[double]] $Variable[[S]];
+ static $Primitive[[double]] $StaticField[[S]];
+ static $Primitive[[void]] $StaticMethod[[bar]]() {}
$Primitive[[void]] $Method[[foo]]() {
$Field[[B]] = 123;
this->$Field[[B]] = 156;
this->$Method[[foo]]();
$Method[[foo]]();
- $Variable[[S]] = 90.1;
+ $StaticMethod[[bar]]();
+ $StaticField[[S]] = 90.1;
}
};
$Primitive[[void]] $Function[[foo]]() {
@@ -214,7 +218,7 @@ TEST(SemanticHighlighting, GetsCorrectTo
$LocalVariable[[AA]].$Field[[B]] += 2;
$LocalVariable[[AA]].$Method[[foo]]();
$LocalVariable[[AA]].$Field[[E]].$Field[[C]];
- $Class[[A]]::$Variable[[S]] = 90;
+ $Class[[A]]::$StaticField[[S]] = 90;
}
)cpp",
R"cpp(
@@ -629,4 +633,4 @@ TEST(SemanticHighlighting, DiffBeyondThe
} // namespace
} // namespace clangd
-} // namespace clang
+} // namespace clang
\ No newline at end of file
More information about the cfe-commits
mailing list