hokein created this revision. hokein added a reviewer: ilya-biryukov. Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay. Herald added a project: clang.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D69506 Files: clang-tools-extra/clangd/SemanticHighlighting.cpp 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 @@ -584,6 +584,11 @@ return $TemplateParameter[[T]]::$DependentName[[Field]]; } }; + )cpp", + // Highlighting the using decl as the underlying using shadow decl. + R"cpp( + void $Function[[foo]](); + using ::$Function[[foo]]; )cpp"}; for (const auto &TestCase : TestCases) { checkHighlightings(TestCase); Index: clang-tools-extra/clangd/SemanticHighlighting.cpp =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.cpp +++ clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -48,6 +48,17 @@ // And fallback to a generic kind if this fails. return HighlightingKind::Typedef; } + if (auto *UD = dyn_cast<UsingDecl>(D)) { + if (UD->shadow_size() == 0) + return llvm::None; // Should we add a new highlighting kind? + // Highlight the using decl as one of the underlying shadow decls. + UsingShadowDecl *Selected = *UD->shadow_begin(); + llvm::for_each(UD->shadows(), [&Selected](UsingShadowDecl *D) { + if (D->getLocation() < Selected->getLocation()) + Selected = D; + }); + return kindForDecl(Selected->getTargetDecl()); + } // We highlight class decls, constructor decls and destructor decls as // `Class` type. The destructor decls are handled in `VisitTagTypeLoc` (we // will visit a TypeLoc where the underlying Type is a CXXRecordDecl).
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -584,6 +584,11 @@ return $TemplateParameter[[T]]::$DependentName[[Field]]; } }; + )cpp", + // Highlighting the using decl as the underlying using shadow decl. + R"cpp( + void $Function[[foo]](); + using ::$Function[[foo]]; )cpp"}; for (const auto &TestCase : TestCases) { checkHighlightings(TestCase); Index: clang-tools-extra/clangd/SemanticHighlighting.cpp =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.cpp +++ clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -48,6 +48,17 @@ // And fallback to a generic kind if this fails. return HighlightingKind::Typedef; } + if (auto *UD = dyn_cast<UsingDecl>(D)) { + if (UD->shadow_size() == 0) + return llvm::None; // Should we add a new highlighting kind? + // Highlight the using decl as one of the underlying shadow decls. + UsingShadowDecl *Selected = *UD->shadow_begin(); + llvm::for_each(UD->shadows(), [&Selected](UsingShadowDecl *D) { + if (D->getLocation() < Selected->getLocation()) + Selected = D; + }); + return kindForDecl(Selected->getTargetDecl()); + } // We highlight class decls, constructor decls and destructor decls as // `Class` type. The destructor decls are handled in `VisitTagTypeLoc` (we // will visit a TypeLoc where the underlying Type is a CXXRecordDecl).
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits