Skip to content

Commit e9b62ce

Browse files
authored
Add public member-wise initializer to 3 types (#484)
* Add public member-wise initializer for LinkDestinationSummary * Fix double optional LinkDestinationSummary.Variant title * Add public member-wise initializer for LinkDestinationSummary.Variant * Add public member-wise initializer for OutOfProcessReferenceResolver.ResolvedInformation * Fix minor typo in initializer documentation comment
1 parent 60535d9 commit e9b62ce

File tree

2 files changed

+119
-3
lines changed

2 files changed

+119
-3
lines changed

Sources/SwiftDocC/Infrastructure/External Data/OutOfProcessReferenceResolver.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,34 @@ extension OutOfProcessReferenceResolver {
851851
///
852852
/// If the resolver information has a declaration but the variant doesn't, this property will be `Optional.some(nil)`.
853853
public let declarationFragments: VariantValue<DeclarationFragments?>
854+
855+
/// Creates a new resolved information variant with the values that are different from the resolved information values.
856+
///
857+
/// - Parameters:
858+
/// - traits: The traits of the variant.
859+
/// - kind: The resolved kind.
860+
/// - url: The resolved URL.
861+
/// - title: The resolved title
862+
/// - abstract: The resolved (plain text) abstract.
863+
/// - language: The resolved language.
864+
/// - declarationFragments: The resolved declaration fragments, if any.
865+
public init(
866+
traits: [RenderNode.Variant.Trait],
867+
kind: VariantValue<DocumentationNode.Kind> = nil,
868+
url: VariantValue<URL> = nil,
869+
title: VariantValue<String> = nil,
870+
abstract: VariantValue<String> = nil,
871+
language: VariantValue<SourceLanguage> = nil,
872+
declarationFragments: VariantValue<DeclarationFragments?> = nil
873+
) {
874+
self.traits = traits
875+
self.kind = kind
876+
self.url = url
877+
self.title = title
878+
self.abstract = abstract
879+
self.language = language
880+
self.declarationFragments = declarationFragments
881+
}
854882
}
855883
}
856884

Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public struct LinkDestinationSummary: Codable, Equatable {
176176
public let relativePresentationURL: VariantValue<URL>
177177

178178
/// The title of the variant or `nil` if the title is the same as the summarized element.
179-
public let title: VariantValue<String?>
179+
public let title: VariantValue<String>
180180

181181
/// The abstract of the variant or `nil` if the abstract is the same as the summarized element.
182182
///
@@ -198,14 +198,102 @@ public struct LinkDestinationSummary: Codable, Equatable {
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?>
200200

201-
/// Images that are used to represent the summarized element.
201+
/// Images that are used to represent the summarized element or `nil` if the images are the same as the summarized element.
202202
///
203203
/// If the summarized element has an image but the variant doesn't, this property will be `Optional.some(nil)`.
204204
public let topicImages: VariantValue<[TopicImage]?>
205+
206+
/// Creates a new summary variant with the values that are different from the main summarized values.
207+
///
208+
/// - Parameters:
209+
/// - traits: The traits of the variant.
210+
/// - kind: The kind of the variant or `nil` if the kind is the same as the summarized element.
211+
/// - language: The source language of the variant or `nil` if the kind is the same as the summarized element.
212+
/// - relativePresentationURL: The relative presentation URL of the variant or `nil` if the relative is the same as the summarized element.
213+
/// - title: The title of the variant or `nil` if the title is the same as the summarized element.
214+
/// - abstract: The abstract of the variant or `nil` if the abstract is the same as the summarized element.
215+
/// - taskGroups: The taskGroups of the variant or `nil` if the taskGroups is the same as the summarized element.
216+
/// - 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.
218+
/// - topicImages: Images that are used to represent the summarized element or `nil` if the images are the same as the summarized element.
219+
public init(
220+
traits: [RenderNode.Variant.Trait],
221+
kind: VariantValue<DocumentationNode.Kind> = nil,
222+
language: VariantValue<SourceLanguage> = nil,
223+
relativePresentationURL: VariantValue<URL> = nil,
224+
title: VariantValue<String> = nil,
225+
abstract: VariantValue<LinkDestinationSummary.Abstract?> = nil,
226+
taskGroups: VariantValue<[LinkDestinationSummary.TaskGroup]?> = nil,
227+
usr: VariantValue<String?> = nil,
228+
declarationFragments: VariantValue<LinkDestinationSummary.DeclarationFragments?> = nil,
229+
topicImages: VariantValue<[TopicImage]?> = nil
230+
) {
231+
self.traits = traits
232+
self.kind = kind
233+
self.language = language
234+
self.relativePresentationURL = relativePresentationURL
235+
self.title = title
236+
self.abstract = abstract
237+
self.taskGroups = taskGroups
238+
self.usr = usr
239+
self.declarationFragments = declarationFragments
240+
self.topicImages = topicImages
241+
}
205242
}
206243

207244
/// The variants of content (kind, title, abstract, path, urs, declaration, and task groups) for this summarized element.
208245
public let variants: [Variant]
246+
247+
/// Creates a new summary of an element that can be linked to from outside the local documentation.
248+
///
249+
/// - Parameters:
250+
/// - kind: The kind of the summarized element.
251+
/// - language: The language of the summarized element.
252+
/// - relativePresentationURL: The relative presentation URL for this element.
253+
/// - referenceURL: The resolved topic reference URL to this element.
254+
/// - title: The title of the summarized element.
255+
/// - abstract: The abstract of the summarized element.
256+
/// - availableLanguages: All the languages in which the summarized element is available.
257+
/// - platforms: Information about the platforms for which the summarized element is available.
258+
/// - taskGroups: The reference URLs of the summarized element's children, grouped by their task groups.
259+
/// - 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.
261+
/// - redirects: Any previous URLs for this element, or `nil` if this element has no previous URLs.
262+
/// - topicImages: Images that are used to represent the summarized element, or `nil` if this element has no topic images.
263+
/// - references: References used in the content of the summarized element, or `nil` if this element has no references to other content.
264+
/// - variants: The variants of content (kind, title, abstract, path, urs, declaration, and task groups) for this summarized element.
265+
public init(
266+
kind: DocumentationNode.Kind,
267+
language: SourceLanguage,
268+
relativePresentationURL: URL,
269+
referenceURL: URL, title: String,
270+
abstract: LinkDestinationSummary.Abstract? = nil,
271+
availableLanguages: Set<SourceLanguage>,
272+
platforms: [LinkDestinationSummary.PlatformAvailability]? = nil,
273+
taskGroups: [LinkDestinationSummary.TaskGroup]? = nil,
274+
usr: String? = nil,
275+
declarationFragments: LinkDestinationSummary.DeclarationFragments? = nil,
276+
redirects: [URL]? = nil,
277+
topicImages: [TopicImage]? = nil,
278+
references: [RenderReference]? = nil,
279+
variants: [LinkDestinationSummary.Variant]
280+
) {
281+
self.kind = kind
282+
self.language = language
283+
self.relativePresentationURL = relativePresentationURL
284+
self.referenceURL = referenceURL
285+
self.title = title
286+
self.abstract = abstract
287+
self.availableLanguages = availableLanguages
288+
self.platforms = platforms
289+
self.taskGroups = taskGroups
290+
self.usr = usr
291+
self.declarationFragments = declarationFragments
292+
self.redirects = redirects
293+
self.topicImages = topicImages
294+
self.references = references
295+
self.variants = variants
296+
}
209297
}
210298

211299
// MARK: - Accessing the externally linkable elements
@@ -569,7 +657,7 @@ extension LinkDestinationSummary.Variant {
569657
language = nil
570658
}
571659
relativePresentationURL = try container.decodeIfPresent(URL.self, forKey: .relativePresentationURL)
572-
title = try container.decodeIfPresent(String?.self, forKey: .title)
660+
title = try container.decodeIfPresent(String.self, forKey: .title)
573661
abstract = try container.decodeIfPresent(LinkDestinationSummary.Abstract?.self, forKey: .abstract)
574662
usr = try container.decodeIfPresent(String?.self, forKey: .usr)
575663
declarationFragments = try container.decodeIfPresent(LinkDestinationSummary.DeclarationFragments?.self, forKey: .declarationFragments)

0 commit comments

Comments
 (0)