[PATCH] D64613: [clangd] Type hierarchy: don't resolve parents if the client only asked for children

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 11 20:29:22 PDT 2019


nridge created this revision.
nridge added a reviewer: sammccall.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64613

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp


Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -630,7 +630,8 @@
   ASSERT_TRUE(bool(Result));
   EXPECT_THAT(
       *Result,
-      AllOf(WithName("Parent"), WithKind(SymbolKind::Struct), Parents(),
+      AllOf(WithName("Parent"), WithKind(SymbolKind::Struct),
+            ParentsNotResolved(),
             Children(AllOf(WithName("Child1"), WithKind(SymbolKind::Struct),
                            ParentsNotResolved(), ChildrenNotResolved()))));
 
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1134,9 +1134,9 @@
 
 static Optional<TypeHierarchyItem>
 getTypeAncestors(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
-                 RecursionProtectionSet &RPSet) {
+                 RecursionProtectionSet &RPSet, bool ResolveParents = true) {
   Optional<TypeHierarchyItem> Result = declToTypeHierarchyItem(ASTCtx, CXXRD);
-  if (!Result)
+  if (!Result || !ResolveParents)
     return Result;
 
   Result->parents.emplace();
@@ -1232,8 +1232,10 @@
     return llvm::None;
 
   RecursionProtectionSet RPSet;
+  bool ResolveParents = (Direction == TypeHierarchyDirection::Parents ||
+                         Direction == TypeHierarchyDirection::Both);
   Optional<TypeHierarchyItem> Result =
-      getTypeAncestors(*CXXRD, AST.getASTContext(), RPSet);
+      getTypeAncestors(*CXXRD, AST.getASTContext(), RPSet, ResolveParents);
   if (!Result)
     return Result;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64613.209407.patch
Type: text/x-patch
Size: 1737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190712/1fb65b96/attachment-0001.bin>


More information about the cfe-commits mailing list