Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.h =================================================================== --- clang-tools-extra/trunk/clangd/SemanticHighlighting.h +++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h @@ -29,7 +29,9 @@ Parameter, Function, Method, + StaticMethod, Field, + StaticField, Class, Enum, EnumConstant, Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp =================================================================== --- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp +++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp @@ -205,8 +205,9 @@ addToken(Loc, HighlightingKind::Class); return; } - if (isa(D)) { - addToken(Loc, HighlightingKind::Method); + if (auto *MD = dyn_cast(D)) { + addToken(Loc, MD->isStatic() ? HighlightingKind::StaticMethod + : HighlightingKind::Method); return; } if (isa(D)) { @@ -226,8 +227,10 @@ return; } if (const VarDecl *VD = dyn_cast(D)) { - addToken(Loc, VD->isLocalVarDecl() ? HighlightingKind::LocalVariable - : HighlightingKind::Variable); + addToken(Loc, VD->isStaticDataMember() + ? HighlightingKind::StaticField + : VD->isLocalVarDecl() ? HighlightingKind::LocalVariable + : HighlightingKind::Variable); return; } if (isa(D)) { @@ -435,6 +438,8 @@ 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 @@ 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: Index: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test =================================================================== --- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test +++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test @@ -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": { Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp =================================================================== --- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp +++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp @@ -35,6 +35,7 @@ std::vector getExpectedTokens(Annotations &Test) { static const std::map KindToString{ {HighlightingKind::Variable, "Variable"}, + {HighlightingKind::LocalVariable, "LocalVariable"}, {HighlightingKind::Parameter, "Parameter"}, {HighlightingKind::Function, "Function"}, {HighlightingKind::Class, "Class"}, @@ -42,10 +43,11 @@ {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 ExpectedTokens; for (const auto &KindString : KindToString) { std::vector Toks = makeHighlightingTokens( @@ -200,13 +202,15 @@ 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 @@ $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 @@ } // namespace } // namespace clangd -} // namespace clang +} // namespace clang \ No newline at end of file