Skip to content

Commit 5a3e31d

Browse files
committed
Use the abbreviated declaration fragments in LinkDestinationSummary
LinkDestinationSummary contains a summary of an element that you can link to from outside the documentation bundle. [1] This information is meant to be used by a server to provide information to an out-of-process resolver to resolve links to external entities, so that the partner implementation of `LinkDestinationSummary` is `OutOfProcessReferenceResolver.ResolvedInformation` [2]. However, currently `OutOfProcessReferenceResolver.ResolvedInformation. declarationFragments` is expecting the abbreviated declaration fragments, but we are storing the full fragments instead. [3] Instead, we should be storing the abbreviated declaration fragments, which are stored as the `subHeading` of the symbol. [4] This subheading is further processed during the render node transformation phase [5], and stored as `renderNode.metadata.fragmentsVariants`. This commit modifies `LinkDestinationSummary` such that its declaration fragments are the abbreviated declaration fragments from `renderNode.metadata.fragmentsVariants` rather than the full declaration fragments. The final result will be that declaration fragments for external links will behave the same as local links when referencing them in the Topics section. They will both now use the abbreviated declaration fragments. [1]: https://github.com/swiftlang/swift-docc/blob/65aaf926ec079ddbd40f29540d4180a70af99e5e/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift#L66 [2]: https://github.com/swiftlang/swift-docc/blob/65aaf926ec079ddbd40f29540d4180a70af99e5e/Sources/SwiftDocC/Infrastructure/External%20Data/OutOfProcessReferenceResolver.swift#L558-L562 [3]: https://github.com/swiftlang/swift-docc/blob/65aaf926ec079ddbd40f29540d4180a70af99e5e/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift#L445 [4]: https://github.com/swiftlang/swift-docc-symbolkit/blob/ebe89c7da4cf03ded04cd708f3399087c6f2dad7/Sources/SymbolKit/SymbolGraph/Symbol/Names.swift#L28-L31
1 parent d666b7b commit 5a3e31d

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
137137

138138
/// The rendered fragments of a symbol's declaration.
139139
public typealias DeclarationFragments = [DeclarationRenderSection.Token]
140-
/// The fragments for this symbol's declaration, or `nil` if the summarized element isn't a symbol.
140+
/// The abbreviated fragments for this symbol's declaration, or `nil` if the summarized element isn't a symbol.
141141
public let declarationFragments: DeclarationFragments?
142142

143143
/// Any previous URLs for this element.
@@ -193,7 +193,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
193193
/// If the summarized element has a precise symbol identifier but the variant doesn't, this property will be `Optional.some(nil)`.
194194
public let usr: VariantValue<String?>
195195

196-
/// The declaration of the variant or `nil` if the declaration is the same as the summarized element.
196+
/// The abbreviated declaration of the variant or `nil` if the declaration is the same as the summarized element.
197197
///
198198
/// If the summarized element has a declaration but the variant doesn't, this property will be `Optional.some(nil)`.
199199
public let declarationFragments: VariantValue<DeclarationFragments?>
@@ -214,7 +214,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
214214
/// - abstract: The abstract of the variant or `nil` if the abstract is the same as the summarized element.
215215
/// - taskGroups: The taskGroups of the variant or `nil` if the taskGroups is the same as the summarized element.
216216
/// - usr: The precise symbol identifier of the variant or `nil` if the precise symbol identifier is the same as the summarized element.
217-
/// - declarationFragments: The declaration of the variant or `nil` if the declaration is the same as the summarized element.
217+
/// - declarationFragments: The abbreviated declaration of the variant or `nil` if the declaration is the same as the summarized element.
218218
/// - topicImages: Images that are used to represent the summarized element or `nil` if the images are the same as the summarized element.
219219
public init(
220220
traits: [RenderNode.Variant.Trait],
@@ -257,7 +257,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
257257
/// - platforms: Information about the platforms for which the summarized element is available.
258258
/// - taskGroups: The reference URLs of the summarized element's children, grouped by their task groups.
259259
/// - usr: The unique, precise identifier for this symbol that you use to reference it across different systems, or `nil` if the summarized element isn't a symbol.
260-
/// - declarationFragments: The fragments for this symbol's declaration, or `nil` if the summarized element isn't a symbol.
260+
/// - declarationFragments: The abbreviated fragments for this symbol's declaration, or `nil` if the summarized element isn't a symbol.
261261
/// - redirects: Any previous URLs for this element, or `nil` if this element has no previous URLs.
262262
/// - topicImages: Images that are used to represent the summarized element, or `nil` if this element has no topic images.
263263
/// - references: References used in the content of the summarized element, or `nil` if this element has no references to other content.
@@ -442,24 +442,38 @@ extension LinkDestinationSummary {
442442

443443
let abstract = renderSymbolAbstract(symbol.abstractVariants[summaryTrait] ?? symbol.abstract)
444444
let usr = symbol.externalIDVariants[summaryTrait] ?? symbol.externalID
445-
let declaration = (symbol.declarationVariants[summaryTrait] ?? symbol.declaration).renderDeclarationTokens()
446445
let language = documentationNode.sourceLanguage
447-
446+
// Use the abbreviated declaration fragments instead of the full declaration fragments.
447+
// These have been derived from the symbol's subheading declaration fragments as part of rendering.
448+
// We only want an abbreviated version of the declaration in the link summary (for display in Topic sections, the navigator, etc.).
449+
// Otherwise, the declaration would be too verbose.
450+
//
451+
// However if no abbreviated declaration fragments are available, use the full declaration fragments instead.
452+
// In this case, they are assumed to be the same.
453+
let declaration = renderNode.metadata.fragmentsVariants.value(for: language) ?? (symbol.declarationVariants[summaryTrait] ?? symbol.declaration).renderDeclarationTokens()
454+
448455
let variants: [Variant] = documentationNode.availableVariantTraits.compactMap { trait in
449456
// Skip the variant for the summarized elements source language.
450457
guard let interfaceLanguage = trait.interfaceLanguage, interfaceLanguage != documentationNode.sourceLanguage.id else {
451458
return nil
452459
}
453460

454-
let declarationVariant = symbol.declarationVariants[trait]?.renderDeclarationTokens()
455-
456461
let abstractVariant: Variant.VariantValue<Abstract?> = symbol.abstractVariants[trait].map { renderSymbolAbstract($0) }
457462

458463
func nilIfEqual<Value: Equatable>(main: Value, variant: Value?) -> Value? {
459464
return main == variant ? nil : variant
460465
}
461466

462467
let variantTraits = [RenderNode.Variant.Trait.interfaceLanguage(interfaceLanguage)]
468+
469+
// Use the abbreviated declaration fragments instead of the full declaration fragments.
470+
// These have been derived from the symbol's subheading declaration fragments as part of rendering.
471+
// We only want an abbreviated version of the declaration in the link summary (for display in Topic sections, the navigator, etc.).
472+
// Otherwise, the declaration would be too verbose.
473+
//
474+
// However if no abbreviated declaration fragments are available, use the full declaration fragments instead.
475+
// In this case, they are assumed to be the same.
476+
let declarationVariant = renderNode.metadata.fragmentsVariants.value(for: variantTraits) ?? symbol.declarationVariants[trait]?.renderDeclarationTokens()
463477
return Variant(
464478
traits: variantTraits,
465479
kind: nilIfEqual(main: kind, variant: symbol.kindVariants[trait].map { DocumentationNode.kind(forKind: $0.identifier) }),

Tests/SwiftDocCTests/LinkTargets/LinkDestinationSummaryTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ class ExternalLinkableTests: XCTestCase {
294294
.init(text: " ", kind: .text, identifier: nil),
295295
.init(text: "globalFunction", kind: .identifier, identifier: nil),
296296
.init(text: "(", kind: .text, identifier: nil),
297-
.init(text: "_", kind: .identifier, identifier: nil),
298-
.init(text: ": ", kind: .text, identifier: nil),
299297
.init(text: "Data", kind: .typeIdentifier, identifier: nil, preciseIdentifier: "s:10Foundation4DataV"),
300298
.init(text: ", ", kind: .text, identifier: nil),
301299
.init(text: "considering", kind: .identifier, identifier: nil),

0 commit comments

Comments
 (0)