Skip to content

Commit 04867f1

Browse files
committed
Rename fullName to plainTextDeclaration in LinkDestinationSummary
`plainTextDeclaration` is clearer and makes it harder to confuse it with `title`. It is also closer to how the value is derived. Also updates the JSON schema in `LinkableEntities.json` to add the new `plainTextDeclaration` property to the `LinkDestinationSummary` and `LinkDestinationSummaryVariant` schemas.
1 parent 7cddb9e commit 04867f1

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

Sources/SwiftDocC/Infrastructure/Link Resolution/ExternalPathHierarchyResolver.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ final class ExternalPathHierarchyResolver {
5858
return collidingNode.name
5959
}
6060
if let symbolID = collidingNode.symbol?.identifier {
61-
if symbolID.interfaceLanguage == summary.language.id, let fullName = summary.fullName {
62-
return fullName
61+
if symbolID.interfaceLanguage == summary.language.id, let plainTextDeclaration = summary.plainTextDeclaration {
62+
return plainTextDeclaration
6363
}
6464
if let variant = summary.variants.first(where: { $0.traits.contains(.interfaceLanguage(symbolID.interfaceLanguage)) }),
65-
let fullName = variant.fullName ?? summary.fullName
65+
let plainTextDeclaration = variant.plainTextDeclaration ?? summary.plainTextDeclaration
6666
{
67-
return fullName
67+
return plainTextDeclaration
6868
}
6969
}
7070
return summary.title

Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public struct LinkDestinationSummary: Codable, Equatable {
135135
/// 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.
136136
public let usr: String?
137137

138-
/// The full name of this symbol, derived from its full declaration fragments, or `nil` if the summarized element isn't a symbol.
139-
public let fullName: String?
138+
/// The plain text declaration of this symbol, derived from its full declaration fragments, or `nil` if the summarized element isn't a symbol.
139+
public let plainTextDeclaration: String?
140140

141141
/// The rendered fragments of a symbol's declaration.
142142
public typealias DeclarationFragments = [DeclarationRenderSection.Token]
@@ -199,10 +199,10 @@ public struct LinkDestinationSummary: Codable, Equatable {
199199
/// If the summarized element has a precise symbol identifier but the variant doesn't, this property will be `Optional.some(nil)`.
200200
public let usr: VariantValue<String?>
201201

202-
/// The full name of this symbol, derived from its full declaration fragments, or `nil` if the precise symbol identifier is the same as the summarized element.
202+
/// The plain text declaration of this symbol, derived from its full declaration fragments, or `nil` if the precise symbol identifier is the same as the summarized element.
203203
///
204-
/// If the summarized element has a full name but the variant doesn't, this property will be `Optional.some(nil)`.
205-
public let fullName: VariantValue<String?>
204+
/// If the summarized element has a plain text declaration but the variant doesn't, this property will be `Optional.some(nil)`.
205+
public let plainTextDeclaration: VariantValue<String?>
206206

207207
/// The abbreviated declaration of the variant, to display in links, or `nil` if the declaration is the same as the summarized element.
208208
///
@@ -231,7 +231,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
231231
/// - abstract: The abstract of the variant or `nil` if the abstract is the same as the summarized element.
232232
/// - taskGroups: The taskGroups of the variant or `nil` if the taskGroups is the same as the summarized element.
233233
/// - usr: The precise symbol identifier of the variant or `nil` if the precise symbol identifier is the same as the summarized element.
234-
/// - fullName: The full name of this symbol, derived from its full declaration fragments, or `nil` if the precise symbol identifier is the same as the summarized element.
234+
/// - plainTextDeclaration: The plain text declaration of this symbol, derived from its full declaration fragments, or `nil` if the precise symbol identifier is the same as the summarized element.
235235
/// - declarationFragments: The abbreviated declaration of the variant, to display in links, or `nil` if the declaration is the same as the summarized element.
236236
/// - navigatorTitle: The abbreviated declaration for this symbol's declaration, to display in navigation, or `nil` if the declaration is the same as the summarized element.
237237
public init(
@@ -243,7 +243,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
243243
abstract: VariantValue<LinkDestinationSummary.Abstract?> = nil,
244244
taskGroups: VariantValue<[LinkDestinationSummary.TaskGroup]?> = nil,
245245
usr: VariantValue<String?> = nil,
246-
fullName: VariantValue<String?> = nil,
246+
plainTextDeclaration: VariantValue<String?> = nil,
247247
declarationFragments: VariantValue<LinkDestinationSummary.DeclarationFragments?> = nil,
248248
navigatorTitle: VariantValue<LinkDestinationSummary.DeclarationFragments?> = nil
249249
) {
@@ -255,12 +255,12 @@ public struct LinkDestinationSummary: Codable, Equatable {
255255
self.abstract = abstract
256256
self.taskGroups = taskGroups
257257
self.usr = usr
258-
self.fullName = fullName
258+
self.plainTextDeclaration = plainTextDeclaration
259259
self.declarationFragments = declarationFragments
260260
self.navigatorTitle = navigatorTitle
261261
}
262262

263-
@available(*, deprecated, renamed: "init(traits:kind:language:relativePresentationURL:title:abstract:taskGroups:usr:fullName:declarationFragments:navigatorTitle:)", message: "Use `init(traits:kind:language:relativePresentationURL:title:abstract:taskGroups:usr:fullName:declarationFragments:navigatorTitle:)` instead. `TopicRenderReference` doesn't support variant specific topic images. This property will be removed after 6.3 is released")
263+
@available(*, deprecated, renamed: "init(traits:kind:language:relativePresentationURL:title:abstract:taskGroups:usr:plainTextDeclaration:declarationFragments:navigatorTitle:)", message: "Use `init(traits:kind:language:relativePresentationURL:title:abstract:taskGroups:usr:plainTextDeclaration:declarationFragments:navigatorTitle:)` instead. `TopicRenderReference` doesn't support variant specific topic images. This property will be removed after 6.3 is released")
264264
public init(
265265
traits: [RenderNode.Variant.Trait],
266266
kind: VariantValue<DocumentationNode.Kind> = nil,
@@ -270,7 +270,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
270270
abstract: VariantValue<LinkDestinationSummary.Abstract?> = nil,
271271
taskGroups: VariantValue<[LinkDestinationSummary.TaskGroup]?> = nil,
272272
usr: VariantValue<String?> = nil,
273-
fullName: VariantValue<String?> = nil,
273+
plainTextDeclaration: VariantValue<String?> = nil,
274274
declarationFragments: VariantValue<LinkDestinationSummary.DeclarationFragments?> = nil,
275275
navigatorTitle: VariantValue<LinkDestinationSummary.DeclarationFragments?> = nil,
276276
topicImages: VariantValue<[TopicImage]?> = nil
@@ -284,7 +284,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
284284
abstract: abstract,
285285
taskGroups: taskGroups,
286286
usr: usr,
287-
fullName: fullName,
287+
plainTextDeclaration: plainTextDeclaration,
288288
declarationFragments: declarationFragments,
289289
navigatorTitle: navigatorTitle
290290
)
@@ -307,7 +307,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
307307
/// - platforms: Information about the platforms for which the summarized element is available.
308308
/// - taskGroups: The reference URLs of the summarized element's children, grouped by their task groups.
309309
/// - 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.
310-
/// - fullName: The full name of this symbol, derived from its full declaration fragments, or `nil` if the summarized element isn't a symbol.
310+
/// - plainTextDeclaration: The plain text declaration of this symbol, derived from its full declaration fragments, or `nil` if the summarized element isn't a symbol.
311311
/// - declarationFragments: The abbreviated fragments for this symbol's declaration, to display in links, or `nil` if the summarized element isn't a symbol.
312312
/// - navigatorTitle: The abbreviated fragments for this symbol's declaration, to display in navigation, or `nil` if the summarized element isn't a symbol.
313313
/// - redirects: Any previous URLs for this element, or `nil` if this element has no previous URLs.
@@ -324,7 +324,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
324324
platforms: [LinkDestinationSummary.PlatformAvailability]? = nil,
325325
taskGroups: [LinkDestinationSummary.TaskGroup]? = nil,
326326
usr: String? = nil,
327-
fullName: String? = nil,
327+
plainTextDeclaration: String? = nil,
328328
declarationFragments: LinkDestinationSummary.DeclarationFragments? = nil,
329329
navigatorTitle: LinkDestinationSummary.DeclarationFragments? = nil,
330330
redirects: [URL]? = nil,
@@ -342,7 +342,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
342342
self.platforms = platforms
343343
self.taskGroups = taskGroups
344344
self.usr = usr
345-
self.fullName = fullName
345+
self.plainTextDeclaration = plainTextDeclaration
346346
self.declarationFragments = declarationFragments
347347
self.navigatorTitle = navigatorTitle
348348
self.redirects = redirects
@@ -498,7 +498,7 @@ extension LinkDestinationSummary {
498498

499499
let abstract = renderSymbolAbstract(symbol.abstractVariants[summaryTrait] ?? symbol.abstract)
500500
let usr = symbol.externalIDVariants[summaryTrait] ?? symbol.externalID
501-
let fullName = symbol.fullName(for: summaryTrait)
501+
let plainTextDeclaration = symbol.plainTextDeclaration(for: summaryTrait)
502502
let language = documentationNode.sourceLanguage
503503
// Use the abbreviated declaration fragments instead of the full declaration fragments.
504504
// These have been derived from the symbol's subheading declaration fragments as part of rendering.
@@ -522,7 +522,7 @@ extension LinkDestinationSummary {
522522
return main == variant ? nil : variant
523523
}
524524

525-
let fullNameVariant = symbol.fullName(for: trait)
525+
let plainTextDeclarationVariant = symbol.plainTextDeclaration(for: trait)
526526
let variantTraits = [RenderNode.Variant.Trait.interfaceLanguage(interfaceLanguage)]
527527

528528
// Use the abbreviated declaration fragments instead of the full declaration fragments.
@@ -543,7 +543,7 @@ extension LinkDestinationSummary {
543543
abstract: nilIfEqual(main: abstract, variant: abstractVariant),
544544
taskGroups: nilIfEqual(main: taskGroups, variant: taskGroupVariants[variantTraits]),
545545
usr: nil, // The symbol variant uses the same USR
546-
fullName: nilIfEqual(main: fullName, variant: fullNameVariant),
546+
plainTextDeclaration: nilIfEqual(main: plainTextDeclaration, variant: plainTextDeclarationVariant),
547547
declarationFragments: nilIfEqual(main: declaration, variant: declarationVariant),
548548
navigatorTitle: nilIfEqual(main: navigatorTitle, variant: navigatorTitleVariant)
549549
)
@@ -564,7 +564,7 @@ extension LinkDestinationSummary {
564564
platforms: platforms,
565565
taskGroups: taskGroups,
566566
usr: usr,
567-
fullName: fullName,
567+
plainTextDeclaration: plainTextDeclaration,
568568
declarationFragments: declaration,
569569
navigatorTitle: navigatorTitle,
570570
redirects: redirects,
@@ -648,7 +648,7 @@ extension LinkDestinationSummary {
648648
// Add Codable methods—which include an initializer—in an extension so that it doesn't override the member-wise initializer.
649649
extension LinkDestinationSummary {
650650
enum CodingKeys: String, CodingKey {
651-
case kind, referenceURL, title, abstract, language, taskGroups, usr, availableLanguages, platforms, redirects, topicImages, references, variants, fullName, navigatorTitle
651+
case kind, referenceURL, title, abstract, language, taskGroups, usr, availableLanguages, platforms, redirects, topicImages, references, variants, plainTextDeclaration, navigatorTitle
652652
case relativePresentationURL = "path"
653653
case declarationFragments = "fragments"
654654
}
@@ -680,7 +680,7 @@ extension LinkDestinationSummary {
680680
try container.encodeIfPresent(platforms, forKey: .platforms)
681681
try container.encodeIfPresent(taskGroups, forKey: .taskGroups)
682682
try container.encodeIfPresent(usr, forKey: .usr)
683-
try container.encodeIfPresent(fullName, forKey: .fullName)
683+
try container.encodeIfPresent(plainTextDeclaration, forKey: .plainTextDeclaration)
684684
try container.encodeIfPresent(declarationFragments, forKey: .declarationFragments)
685685
try container.encodeIfPresent(navigatorTitle, forKey: .navigatorTitle)
686686
try container.encodeIfPresent(redirects, forKey: .redirects)
@@ -738,7 +738,7 @@ extension LinkDestinationSummary {
738738
platforms = try container.decodeIfPresent([AvailabilityRenderItem].self, forKey: .platforms)
739739
taskGroups = try container.decodeIfPresent([TaskGroup].self, forKey: .taskGroups)
740740
usr = try container.decodeIfPresent(String.self, forKey: .usr)
741-
fullName = try container.decodeIfPresent(String.self, forKey: .fullName)
741+
plainTextDeclaration = try container.decodeIfPresent(String.self, forKey: .plainTextDeclaration)
742742
declarationFragments = try container.decodeIfPresent(DeclarationFragments.self, forKey: .declarationFragments)
743743
navigatorTitle = try container.decodeIfPresent(DeclarationFragments.self, forKey: .navigatorTitle)
744744
redirects = try container.decodeIfPresent([URL].self, forKey: .redirects)
@@ -753,7 +753,7 @@ extension LinkDestinationSummary {
753753

754754
extension LinkDestinationSummary.Variant {
755755
enum CodingKeys: String, CodingKey {
756-
case traits, kind, title, abstract, language, usr, taskGroups, fullName, navigatorTitle
756+
case traits, kind, title, abstract, language, usr, taskGroups, plainTextDeclaration, navigatorTitle
757757
case relativePresentationURL = "path"
758758
case declarationFragments = "fragments"
759759
}
@@ -779,7 +779,7 @@ extension LinkDestinationSummary.Variant {
779779
}
780780
}
781781
try container.encodeIfPresent(usr, forKey: .usr)
782-
try container.encodeIfPresent(fullName, forKey: .fullName)
782+
try container.encodeIfPresent(plainTextDeclaration, forKey: .plainTextDeclaration)
783783
try container.encodeIfPresent(declarationFragments, forKey: .declarationFragments)
784784
try container.encodeIfPresent(navigatorTitle, forKey: .navigatorTitle)
785785
try container.encodeIfPresent(taskGroups, forKey: .taskGroups)
@@ -822,7 +822,7 @@ extension LinkDestinationSummary.Variant {
822822
title = try container.decodeIfPresent(String.self, forKey: .title)
823823
abstract = try container.decodeIfPresent(LinkDestinationSummary.Abstract?.self, forKey: .abstract)
824824
usr = try container.decodeIfPresent(String?.self, forKey: .usr)
825-
fullName = try container.decodeIfPresent(String?.self, forKey: .fullName)
825+
plainTextDeclaration = try container.decodeIfPresent(String?.self, forKey: .plainTextDeclaration)
826826
declarationFragments = try container.decodeIfPresent(LinkDestinationSummary.DeclarationFragments?.self, forKey: .declarationFragments)
827827
navigatorTitle = try container.decodeIfPresent(LinkDestinationSummary.DeclarationFragments?.self, forKey: .navigatorTitle)
828828
taskGroups = try container.decodeIfPresent([LinkDestinationSummary.TaskGroup]?.self, forKey: .taskGroups)
@@ -934,15 +934,9 @@ private extension Collection {
934934
}
935935
}
936936

937-
private extension Sequence<DeclarationRenderSection.Token> {
938-
func plainTextDeclaration() -> String {
939-
return self.map(\.text).joined().split(whereSeparator: { $0.isWhitespace || $0.isNewline }).joined(separator: " ")
940-
}
941-
}
942-
943937
private extension Symbol {
944-
func fullName(for trait: DocumentationDataVariantsTrait) -> String? {
945-
let fullDeclaration = (self.declarationVariants[trait] ?? self.declaration).renderDeclarationTokens()
946-
return fullDeclaration?.plainTextDeclaration()
938+
func plainTextDeclaration(for trait: DocumentationDataVariantsTrait) -> String? {
939+
guard let fullDeclaration = (self.declarationVariants[trait] ?? self.declaration).mainRenderFragments() else { return nil }
940+
return fullDeclaration.declarationFragments.map(\.spelling).joined().split(whereSeparator: { $0.isWhitespace || $0.isNewline }).joined(separator: " ")
947941
}
948942
}

Sources/SwiftDocC/SwiftDocC.docc/Resources/LinkableEntities.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
"usr": {
6969
"type": "string"
7070
},
71+
"plainTextDeclaration": {
72+
"type": "string"
73+
},
7174
"fragments": {
7275
"type": "array",
7376
"items": {
@@ -158,6 +161,10 @@
158161
"type": "string",
159162
"nullable": true
160163
},
164+
"plainTextDeclaration": {
165+
"type": "string",
166+
"nullable": true
167+
},
161168
"fragments": {
162169
"type": "array",
163170
"items": {

0 commit comments

Comments
 (0)