Skip to content

Commit bef86be

Browse files
committed
Fix language availability for articles See Alsos
rdar://90159299
1 parent 3d7d7c8 commit bef86be

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -698,29 +698,44 @@ public struct RenderNodeTranslator: SemanticVisitor {
698698
}
699699
node.metadata.role = contentRenderer.roleForArticle(article, nodeKind: documentationNode.kind).rawValue
700700

701-
// Authored See Also section
702-
if let seeAlso = article.seeAlso, !seeAlso.taskGroups.isEmpty {
703-
node.seeAlsoSections.append(
704-
contentsOf: renderGroups(
705-
seeAlso,
706-
allowExternalLinks: true,
707-
allowedTraits: documentationNode.availableVariantTraits,
708-
contentCompiler: &contentCompiler
701+
node.seeAlsoSectionsVariants = VariantCollection<[TaskGroupRenderSection]>(
702+
from: documentationNode.availableVariantTraits,
703+
fallbackDefaultValue: []
704+
) { trait in
705+
var seeAlsoSections = [TaskGroupRenderSection]()
706+
707+
// Authored See Also section
708+
if let seeAlso = article.seeAlso, !seeAlso.taskGroups.isEmpty {
709+
seeAlsoSections.append(
710+
contentsOf: renderGroups(
711+
seeAlso,
712+
allowExternalLinks: true,
713+
allowedTraits: [trait],
714+
contentCompiler: &contentCompiler
715+
)
709716
)
710-
)
711-
}
712-
713-
// Automatic See Also section
714-
if let seeAlso = try! AutomaticCuration.seeAlso(for: documentationNode, context: context, bundle: bundle, renderContext: renderContext, renderer: contentRenderer) {
715-
contentCompiler.collectedTopicReferences.append(contentsOf: seeAlso.references)
716-
node.seeAlsoSections.append(TaskGroupRenderSection(
717-
title: seeAlso.title,
718-
abstract: nil,
719-
discussion: nil,
720-
identifiers: seeAlso.references.map { $0.absoluteString },
721-
generated: true
722-
))
723-
}
717+
}
718+
719+
// Automatic See Also section
720+
if let seeAlso = try! AutomaticCuration.seeAlso(
721+
for: documentationNode,
722+
context: context,
723+
bundle: bundle,
724+
renderContext: renderContext,
725+
renderer: contentRenderer
726+
) {
727+
contentCompiler.collectedTopicReferences.append(contentsOf: seeAlso.references)
728+
seeAlsoSections.append(TaskGroupRenderSection(
729+
title: seeAlso.title,
730+
abstract: nil,
731+
discussion: nil,
732+
identifiers: seeAlso.references.map { $0.absoluteString },
733+
generated: true
734+
))
735+
}
736+
737+
return seeAlsoSections
738+
} ?? .init(defaultValue: [])
724739

725740
collectedTopicReferences.append(contentsOf: contentCompiler.collectedTopicReferences)
726741
node.references = createTopicRenderReferences()

Tests/SwiftDocCTests/Model/SemaToRenderNodeMultiLanguageTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ class SemaToRenderNodeMixedLanguageTests: ExperimentalObjectiveCTestCase {
468468
topicSectionIdentifiers: [
469469
"doc://org.swift.MixedLanguageFramework/documentation/MixedLanguageFramework/SwiftOnlyStruct"
470470
],
471+
seeAlsoSectionIdentifiers: [
472+
"doc://org.swift.MixedLanguageFramework/documentation/MixedLanguageFramework/SwiftOnlyStruct",
473+
"doc://org.swift.MixedLanguageFramework/documentation/MixedLanguageFramework/Article",
474+
],
471475
referenceTitles: [
472476
"Article",
473477
"MixedLanguageFramework",
@@ -495,6 +499,9 @@ class SemaToRenderNodeMixedLanguageTests: ExperimentalObjectiveCTestCase {
495499
topicSectionIdentifiers: [
496500
"doc://org.swift.MixedLanguageFramework/documentation/MixedLanguageFramework/_MixedLanguageFrameworkVersionNumber"
497501
],
502+
seeAlsoSectionIdentifiers: [
503+
"doc://org.swift.MixedLanguageFramework/documentation/MixedLanguageFramework/Article",
504+
],
498505
referenceTitles: [
499506
"Article",
500507
"MixedLanguageFramework",
@@ -520,6 +527,7 @@ class SemaToRenderNodeMixedLanguageTests: ExperimentalObjectiveCTestCase {
520527
declarationTokens expectedDeclarationTokens: [String]?,
521528
discussionSection expectedDiscussionSection: [String]?,
522529
topicSectionIdentifiers expectedTopicSectionIdentifiers: [String],
530+
seeAlsoSectionIdentifiers expectedSeeAlsoSectionIdentifiers: [String]? = nil,
523531
referenceTitles expectedReferenceTitles: [String],
524532
referenceFragments expectedReferenceFragments: [String],
525533
failureMessage failureMessageForField: (_ field: String) -> String,
@@ -593,6 +601,16 @@ class SemaToRenderNodeMixedLanguageTests: ExperimentalObjectiveCTestCase {
593601
line: line
594602
)
595603

604+
if let expectedSeeAlsoSectionIdentifiers = expectedSeeAlsoSectionIdentifiers {
605+
XCTAssertEqual(
606+
renderNode.seeAlsoSections.flatMap(\.identifiers),
607+
expectedSeeAlsoSectionIdentifiers,
608+
failureMessageForField("see also sections identifiers"),
609+
file: file,
610+
line: line
611+
)
612+
}
613+
596614
XCTAssertEqual(
597615
renderNode.references.map(\.value).compactMap { reference in
598616
(reference as? TopicRenderReference)?.title

Tests/SwiftDocCTests/Test Bundles/MixedLanguageFramework.docc/APICollection.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ This is an API collection.
1212

1313
- <doc:_MixedLanguageFrameworkVersionNumber>
1414

15+
## See Also
16+
17+
- ``SwiftOnlyStruct``
18+
1519
<!-- Copyright (c) 2022 Apple Inc and the Swift Project authors. All Rights Reserved. -->

0 commit comments

Comments
 (0)