diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -1134,9 +1134,9 @@ static Optional getTypeAncestors(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx, - RecursionProtectionSet &RPSet) { + RecursionProtectionSet &RPSet, bool ResolveParents = true) { Optional 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 Result = - getTypeAncestors(*CXXRD, AST.getASTContext(), RPSet); + getTypeAncestors(*CXXRD, AST.getASTContext(), RPSet, ResolveParents); if (!Result) return Result; diff --git a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp --- a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp +++ b/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()))));