Author: Nathan Ridge Date: 2019-12-05T14:30:53-05:00 New Revision: de3dbc4f41665e60f53eb3d41fcadb2b322cf6f0
URL: https://github.com/llvm/llvm-project/commit/de3dbc4f41665e60f53eb3d41fcadb2b322cf6f0 DIFF: https://github.com/llvm/llvm-project/commit/de3dbc4f41665e60f53eb3d41fcadb2b322cf6f0.diff LOG: [clangd] Highlighting dependent types in more contexts Fixes https://github.com/clangd/clangd/issues/214. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70746 Added: Modified: clang-tools-extra/clangd/SemanticHighlighting.cpp clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 049afb741b27..2b65625ae2d2 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -258,6 +258,25 @@ class CollectExtraHighlightings return true; } + bool VisitDependentTemplateSpecializationTypeLoc( + DependentTemplateSpecializationTypeLoc L) { + H.addToken(L.getTemplateNameLoc(), HighlightingKind::DependentType); + return true; + } + + // findExplicitReferences will walk nested-name-specifiers and + // find anything that can be resolved to a Decl. However, non-leaf + // components of nested-name-specifiers which are dependent names + // (kind "Identifier") cannot be resolved to a decl, so we visit + // them here. + bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Q) { + if (NestedNameSpecifier *NNS = Q.getNestedNameSpecifier()) { + if (NNS->getKind() == NestedNameSpecifier::Identifier) + H.addToken(Q.getLocalBeginLoc(), HighlightingKind::DependentType); + } + return RecursiveASTVisitor::TraverseNestedNameSpecifierLoc(Q); + } + private: HighlightingsBuilder &H; }; diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index 2df0f1c9a579..b353c0bdb4ec 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -630,7 +630,24 @@ TEST(SemanticHighlighting, GetsCorrectTokens) { R"cpp( template <typename... $TemplateParameter[[Elements]]> struct $Class[[TupleSize]] { - static const int $StaticField[[size]] = sizeof...($TemplateParameter[[Elements]]); + static const int $StaticField[[size]] = +sizeof...($TemplateParameter[[Elements]]); + }; + )cpp", + // More dependent types + R"cpp( + template <typename $TemplateParameter[[T]]> + struct $Class[[Waldo]] { + using $Typedef[[Location1]] = typename $TemplateParameter[[T]] + ::$DependentType[[Resolver]]::$DependentType[[Location]]; + using $Typedef[[Location2]] = typename $TemplateParameter[[T]] + ::template $DependentType[[Resolver]]<$TemplateParameter[[T]]> + ::$DependentType[[Location]]; + using $Typedef[[Location3]] = typename $TemplateParameter[[T]] + ::$DependentType[[Resolver]] + ::template $DependentType[[Location]]<$TemplateParameter[[T]]>; + static const int $StaticField[[Value]] = $TemplateParameter[[T]] + ::$DependentType[[Resolver]]::$DependentName[[Value]]; }; )cpp"}; for (const auto &TestCase : TestCases) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits