nridge updated this revision to Diff 224241. nridge added a comment. Updated to use WalkUpFromDependentNameTypeLoc
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67901/new/ https://reviews.llvm.org/D67901 Files: clang-tools-extra/clangd/SemanticHighlighting.cpp clang-tools-extra/clangd/SemanticHighlighting.h clang-tools-extra/clangd/test/semantic-highlighting.test clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -51,6 +51,9 @@ {HighlightingKind::StaticField, "StaticField"}, {HighlightingKind::Method, "Method"}, {HighlightingKind::StaticMethod, "StaticMethod"}, + {HighlightingKind::Typedef, "Typedef"}, + {HighlightingKind::DependentType, "DependentType"}, + {HighlightingKind::DependentName, "DependentName"}, {HighlightingKind::TemplateParameter, "TemplateParameter"}, {HighlightingKind::Primitive, "Primitive"}, {HighlightingKind::Macro, "Macro"}}; @@ -175,7 +178,7 @@ } template<typename $TemplateParameter[[T]]> struct $Class[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> { - typename $TemplateParameter[[T]]::A* $Field[[D]]; + typename $TemplateParameter[[T]]::$DependentType[[A]]* $Field[[D]]; }; $Namespace[[abc]]::$Class[[A]]<$Primitive[[int]]> $Variable[[AA]]; typedef $Namespace[[abc]]::$Class[[A]]<$Primitive[[int]]> $Class[[AAA]]; @@ -523,6 +526,55 @@ $Typedef[[Pointer]], $Typedef[[LVReference]], $Typedef[[RVReference]], $Typedef[[Array]], $Typedef[[MemberPointer]]); }; + )cpp", + R"cpp( + template <class $TemplateParameter[[T]]> + $Primitive[[void]] $Function[[foo]]($TemplateParameter[[T]] $Parameter[[P]]) { + $DependentName[[bar]]($Parameter[[P]]); + } + )cpp", + R"cpp( + class $Class[[A]] { + template <class $TemplateParameter[[T]]> + $Primitive[[void]] $Method[[bar]]($TemplateParameter[[T]]); + }; + + template <class $TemplateParameter[[U]]> + $Primitive[[void]] $Function[[foo]]($TemplateParameter[[U]] $Parameter[[P]]) { + $Class[[A]]().$DependentName[[bar]]($Parameter[[P]]); + } + )cpp", + R"cpp( + struct $Class[[A]] { + template <class $TemplateParameter[[T]]> + static $Primitive[[void]] $StaticMethod[[foo]]($TemplateParameter[[T]]); + }; + + template <class $TemplateParameter[[T]]> + struct $Class[[B]] { + $Primitive[[void]] $Method[[bar]]() { + $Class[[A]]::$DependentName[[foo]]($TemplateParameter[[T]]()); + } + }; + )cpp", + R"cpp( + template <class $TemplateParameter[[T]]> + $Primitive[[void]] $Function[[foo]](typename $TemplateParameter[[T]]::$DependentType[[Type]] + = $TemplateParameter[[T]]::$DependentName[[val]]); + )cpp", + R"cpp( + template <class $TemplateParameter[[T]]> + $Primitive[[void]] $Function[[foo]]($TemplateParameter[[T]] $Parameter[[P]]) { + $Parameter[[P]].$DependentName[[Field]]; + } + )cpp", + R"cpp( + template <class $TemplateParameter[[T]]> + class $Class[[A]] { + $Primitive[[int]] $Method[[foo]]() { + return $TemplateParameter[[T]]::$DependentName[[Field]]; + } + }; )cpp"}; for (const auto &TestCase : TestCases) { checkHighlightings(TestCase); Index: clang-tools-extra/clangd/test/semantic-highlighting.test =================================================================== --- clang-tools-extra/clangd/test/semantic-highlighting.test +++ clang-tools-extra/clangd/test/semantic-highlighting.test @@ -41,6 +41,12 @@ # CHECK-NEXT: "entity.name.type.typedef.cpp" # CHECK-NEXT: ], # CHECK-NEXT: [ +# CHECK-NEXT: "entity.name.type.dependent.cpp" +# CHECK-NEXT: ], +# CHECK-NEXT: [ +# CHECK-NEXT: "entity.name.other.dependent.cpp" +# CHECK-NEXT: ], +# CHECK-NEXT: [ # CHECK-NEXT: "entity.name.namespace.cpp" # CHECK-NEXT: ], # CHECK-NEXT: [ @@ -61,7 +67,7 @@ # CHECK-NEXT: "lines": [ # CHECK-NEXT: { # CHECK-NEXT: "line": 0, -# CHECK-NEXT: "tokens": "AAAAAAADAA4AAAAEAAEAAA==" +# CHECK-NEXT: "tokens": "AAAAAAADABAAAAAEAAEAAA==" # CHECK-NEXT: } # CHECK-NEXT: ], # CHECK-NEXT: "textDocument": { @@ -76,11 +82,11 @@ # CHECK-NEXT: "lines": [ # CHECK-NEXT: { # CHECK-NEXT: "line": 0, -# CHECK-NEXT: "tokens": "AAAAAAADAA4AAAAEAAEAAA==" +# CHECK-NEXT: "tokens": "AAAAAAADABAAAAAEAAEAAA==" # CHECK-NEXT: } # CHECK-NEXT: { # CHECK-NEXT: "line": 1, -# CHECK-NEXT: "tokens": "AAAAAAADAA4AAAAEAAEAAA==" +# CHECK-NEXT: "tokens": "AAAAAAADABAAAAAEAAEAAA==" # CHECK-NEXT: } # CHECK-NEXT: ], # CHECK-NEXT: "textDocument": { @@ -95,7 +101,7 @@ # CHECK-NEXT: "lines": [ # CHECK-NEXT: { # CHECK-NEXT: "line": 1, -# CHECK-NEXT: "tokens": "AAAAAAADAA4AAAAEAAEAAA==" +# CHECK-NEXT: "tokens": "AAAAAAADABAAAAAEAAEAAA==" # CHECK-NEXT: } # CHECK-NEXT: ], # CHECK-NEXT: "textDocument": { Index: clang-tools-extra/clangd/SemanticHighlighting.h =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.h +++ clang-tools-extra/clangd/SemanticHighlighting.h @@ -37,6 +37,8 @@ Enum, EnumConstant, Typedef, + DependentType, + DependentName, Namespace, TemplateParameter, Primitive, Index: clang-tools-extra/clangd/SemanticHighlighting.cpp =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.cpp +++ clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -152,6 +152,30 @@ return true; } + bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { + if (canHighlightName(E->getName())) + addToken(E->getNameLoc(), HighlightingKind::DependentName); + return true; + } + + bool VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { + if (canHighlightName(E->getName())) + addToken(E->getNameLoc(), HighlightingKind::DependentName); + return true; + } + + bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { + if (canHighlightName(E->getDeclName())) + addToken(E->getLocation(), HighlightingKind::DependentName); + return true; + } + + bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) { + if (canHighlightName(E->getMember())) + addToken(E->getMemberLoc(), HighlightingKind::DependentName); + return true; + } + bool VisitNamedDecl(NamedDecl *ND) { if (canHighlightName(ND->getDeclName())) addToken(ND->getLocation(), ND); @@ -187,6 +211,11 @@ return true; } + bool WalkUpFromDependentNameTypeLoc(DependentNameTypeLoc L) { + addToken(L.getNameLoc(), HighlightingKind::DependentType); + return true; + } + bool VisitTypeLoc(TypeLoc TL) { if (auto K = kindForType(TL.getTypePtr())) addToken(TL.getBeginLoc(), *K); @@ -339,6 +368,10 @@ return OS << "EnumConstant"; case HighlightingKind::Typedef: return OS << "Typedef"; + case HighlightingKind::DependentType: + return OS << "DependentType"; + case HighlightingKind::DependentName: + return OS << "DependentName"; case HighlightingKind::Namespace: return OS << "Namespace"; case HighlightingKind::TemplateParameter: @@ -468,6 +501,10 @@ return "variable.other.enummember.cpp"; case HighlightingKind::Typedef: return "entity.name.type.typedef.cpp"; + case HighlightingKind::DependentType: + return "entity.name.type.dependent.cpp"; + case HighlightingKind::DependentName: + return "entity.name.other.dependent.cpp"; case HighlightingKind::Namespace: return "entity.name.namespace.cpp"; case HighlightingKind::TemplateParameter:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits