Skip to content

Commit 1e8eb0a

Browse files
authored
Remove unused code in RenderNodeTranslator (#960)
* Remove unused RenderNodeTranslator source * Remove no-longer-used source parameters * Remove other unused (or assign-only) RenderNodeTranslator properties * Remove unused parameter in private RenderNodeTranslator method * Update newly added tests to not pass nil for removed (unused) parameter
1 parent 34a872d commit 1e8eb0a

File tree

47 files changed

+271
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+271
-480
lines changed

Sources/SwiftDocC/Converter/DocumentationContextConverter.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ public class DocumentationContextConverter {
8383
/// Convert a documentation node into a render node to get a self-contained, persist-able representation of a given topic's data, so you can write it to disk, send it over a network, or otherwise process it.
8484
/// - Parameters:
8585
/// - node: The documentation node to convert.
86-
/// - source: The source file for the documentation node.
8786
/// - Returns: The render node representation of the documentation node.
88-
public func renderNode(for node: DocumentationNode, at source: URL?) throws -> RenderNode? {
87+
public func renderNode(for node: DocumentationNode) throws -> RenderNode? {
8988
guard !node.isVirtual else {
9089
return nil
9190
}
@@ -94,7 +93,6 @@ public class DocumentationContextConverter {
9493
context: context,
9594
bundle: bundle,
9695
identifier: node.reference,
97-
source: source,
9896
renderContext: renderContext,
9997
emitSymbolSourceFileURIs: shouldEmitSymbolSourceFileURIs,
10098
emitSymbolAccessLevels: shouldEmitSymbolAccessLevels,
@@ -103,4 +101,9 @@ public class DocumentationContextConverter {
103101
)
104102
return translator.visit(node.semantic) as? RenderNode
105103
}
104+
105+
@available(*, deprecated, renamed: "renderNode(for:)", message: "Use 'renderNode(for:)' instead. This deprecated API will be removed after 6.1 is released")
106+
public func renderNode(for node: DocumentationNode, at source: URL?) throws -> RenderNode? {
107+
return try self.renderNode(for: node)
108+
}
106109
}

Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ public struct DocumentationNodeConverter {
3535
/// Convert a documentation node into a render node to get a self-contained, persistable representation of a given topic's data, so you can write it to disk, send it over a network, or otherwise process it.
3636
/// - Parameters:
3737
/// - node: The documentation node to convert.
38-
/// - source: The source file for the documentation node.
3938
/// - Returns: The render node representation of the documentation node.
40-
public func convert(_ node: DocumentationNode, at source: URL?) throws -> RenderNode {
41-
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference, source: source)
39+
public func convert(_ node: DocumentationNode) throws -> RenderNode {
40+
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference)
4241
return translator.visit(node.semantic) as! RenderNode
4342
}
43+
44+
@available(*, deprecated, renamed: "convert(_:)", message: "Use 'convert(_:)' instead. This deprecated API will be removed after 6.1 is released")
45+
public func convert(_ node: DocumentationNode, at source: URL?) throws -> RenderNode {
46+
return try convert(node)
47+
}
4448
}

Sources/SwiftDocC/Infrastructure/DocumentationConverter.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
318318
var conversionProblems: [Problem] = references.concurrentPerform { identifier, results in
319319
// If cancelled skip all concurrent conversion work in this block.
320320
guard !isConversionCancelled() else { return }
321-
322-
let source = context.documentURL(for: identifier)
323321

324322
// Wrap JSON encoding in an autorelease pool to avoid retaining the autoreleased ObjC objects returned by `JSONSerialization`
325323
autoreleasepool {
@@ -330,7 +328,7 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
330328
return
331329
}
332330

333-
guard let renderNode = try converter.renderNode(for: entity, at: source) else {
331+
guard let renderNode = try converter.renderNode(for: entity) else {
334332
// No render node was produced for this entity, so just skip it.
335333
return
336334
}

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
4545
/// Whether the documentation converter should include access level information for symbols.
4646
var shouldEmitSymbolAccessLevels: Bool
4747

48-
/// Whether tutorials that are not curated in a tutorials overview should be translated.
49-
var shouldRenderUncuratedTutorials: Bool = false
50-
5148
/// The source repository where the documentation's sources are hosted.
5249
var sourceRepository: SourceRepository?
5350

@@ -356,7 +353,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
356353

357354
/// Returns a description of the total estimated duration to complete the tutorials of the given technology.
358355
/// - Returns: The estimated duration, or `nil` if there are no tutorials with time estimates.
359-
private func totalEstimatedDuration(for technology: Technology) -> String? {
356+
private func totalEstimatedDuration() -> String? {
360357
var totalDurationMinutes: Int? = nil
361358

362359
for node in context.breadthFirstSearch(from: identifier) {
@@ -381,7 +378,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
381378
node.metadata.title = technology.intro.title
382379
node.metadata.category = technology.name
383380
node.metadata.categoryPathComponent = identifier.url.lastPathComponent
384-
node.metadata.estimatedTime = totalEstimatedDuration(for: technology)
381+
node.metadata.estimatedTime = totalEstimatedDuration()
385382
node.metadata.role = DocumentationContentRenderer.role(for: .technology).rawValue
386383

387384
let documentationNode = try! context.entity(with: identifier)
@@ -974,11 +971,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
974971
return nil
975972
}
976973

977-
/// The current module context for symbols.
978-
private var currentSymbolModuleName: String? = nil
979-
/// The current symbol context.
980-
private var currentSymbol: ResolvedTopicReference? = nil
981-
982974
/// Renders automatically generated task groups
983975
private mutating func renderAutomaticTaskGroupsSection(_ taskGroups: [AutomaticTaskGroupSection], contentCompiler: inout RenderContentCompiler) -> [TaskGroupRenderSection] {
984976
return taskGroups.map { group in
@@ -1207,8 +1199,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
12071199

12081200
var node = RenderNode(identifier: identifier, kind: .symbol)
12091201
var contentCompiler = RenderContentCompiler(context: context, bundle: bundle, identifier: identifier)
1210-
1211-
currentSymbol = identifier
12121202

12131203
/*
12141204
FIXME: We shouldn't be doing this kind of crawling here.
@@ -1673,7 +1663,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
16731663
addReferences(contentCompiler.linkReferences, to: &node)
16741664
addReferences(linkReferences, to: &node)
16751665

1676-
currentSymbol = nil
16771666
return node
16781667
}
16791668

@@ -1745,7 +1734,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
17451734
var context: DocumentationContext
17461735
var bundle: DocumentationBundle
17471736
var identifier: ResolvedTopicReference
1748-
var source: URL?
17491737
var imageReferences: [String: ImageReference] = [:]
17501738
var videoReferences: [String: VideoReference] = [:]
17511739
var fileReferences: [String: FileReference] = [:]
@@ -1952,7 +1940,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
19521940
context: DocumentationContext,
19531941
bundle: DocumentationBundle,
19541942
identifier: ResolvedTopicReference,
1955-
source: URL?,
19561943
renderContext: RenderContext? = nil,
19571944
emitSymbolSourceFileURIs: Bool = false,
19581945
emitSymbolAccessLevels: Bool = false,
@@ -1962,7 +1949,6 @@ public struct RenderNodeTranslator: SemanticVisitor {
19621949
self.context = context
19631950
self.bundle = bundle
19641951
self.identifier = identifier
1965-
self.source = source
19661952
self.renderContext = renderContext
19671953
self.contentRenderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle)
19681954
self.shouldEmitSymbolSourceFileURIs = emitSymbolSourceFileURIs

Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class DocumentationContextConverterTests: XCTestCase {
2727
for identifier in context.knownPages {
2828
let documentationNode = try XCTUnwrap(try context.entity(with: identifier))
2929

30-
let renderNode1 = try perNodeConverter.convert(documentationNode, at: nil)
31-
let renderNode2 = try bulkNodeConverter.renderNode(for: documentationNode, at: nil)
30+
let renderNode1 = try perNodeConverter.convert(documentationNode)
31+
let renderNode2 = try bulkNodeConverter.renderNode(for: documentationNode)
3232

3333
// Compare the two nodes are identical
3434
let data1 = try encoder.encode(renderNode1)
@@ -55,8 +55,7 @@ class DocumentationContextConverterTests: XCTestCase {
5555
renderContext: renderContext,
5656
emitSymbolSourceFileURIs: true)
5757

58-
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(
59-
for: fillIntroducedSymbolNode, at: nil))
58+
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(for: fillIntroducedSymbolNode))
6059
XCTAssertEqual(renderNode.metadata.sourceFileURI, "file:///tmp/FillIntroduced.swift")
6160
}
6261

@@ -66,8 +65,7 @@ class DocumentationContextConverterTests: XCTestCase {
6665
context: context,
6766
renderContext: renderContext)
6867

69-
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(
70-
for: fillIntroducedSymbolNode, at: nil))
68+
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(for: fillIntroducedSymbolNode))
7169
XCTAssertNil(renderNode.metadata.sourceFileURI)
7270
}
7371
}
@@ -88,8 +86,7 @@ class DocumentationContextConverterTests: XCTestCase {
8886
emitSymbolAccessLevels: true
8987
)
9088

91-
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(
92-
for: fillIntroducedSymbolNode, at: nil))
89+
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(for: fillIntroducedSymbolNode))
9390
XCTAssertEqual(renderNode.metadata.symbolAccessLevel, "public")
9491
}
9592

@@ -99,8 +96,7 @@ class DocumentationContextConverterTests: XCTestCase {
9996
context: context,
10097
renderContext: renderContext)
10198

102-
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(
103-
for: fillIntroducedSymbolNode, at: nil))
99+
let renderNode = try XCTUnwrap(documentationContextConverter.renderNode(for: fillIntroducedSymbolNode))
104100
XCTAssertNil(renderNode.metadata.symbolAccessLevel)
105101
}
106102
}

Tests/SwiftDocCTests/Converter/RenderNodeCodableTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,7 @@ class RenderNodeCodableTests: XCTestCase {
203203
)
204204
context.topicGraph.addNode(topicGraphNode)
205205

206-
var translator = RenderNodeTranslator(
207-
context: context,
208-
bundle: bundle,
209-
identifier: reference,
210-
source: nil
211-
)
206+
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: reference)
212207
let node = try XCTUnwrap(translator.visitArticle(article) as? RenderNode)
213208
XCTAssertEqual(node.topicSectionsStyle, .compactGrid)
214209

Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
170170
// For reach topic encode its render node and verify the references are in alphabetical order.
171171
for reference in context.knownPages {
172172
let node = try context.entity(with: reference)
173-
let renderNode = try converter.convert(node, at: nil)
173+
let renderNode = try converter.convert(node)
174174

175175
// Get the encoded JSON as string
176176
let encodedData = try renderNode.encodeToJSON(with: encoder, renderReferenceCache: cache)
@@ -228,7 +228,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
228228
// For reach topic encode its render node and verify the references are in alphabetical order.
229229
for reference in context.knownPages {
230230
let node = try context.entity(with: reference)
231-
let renderNode = try converter.convert(node, at: nil)
231+
let renderNode = try converter.convert(node)
232232

233233
// Get the encoded JSON as string
234234
let encodedData = try renderNode.encodeToJSON(with: encoder)

Tests/SwiftDocCTests/Indexing/IndexingTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IndexingTests: XCTestCase {
1919
let tutorialReference = ResolvedTopicReference(bundleIdentifier: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)
2020
let node = try context.entity(with: tutorialReference)
2121
let tutorial = node.semantic as! Tutorial
22-
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: tutorialReference, source: context.documentURL(for: tutorialReference))
22+
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: tutorialReference)
2323
let renderNode = converter.visit(tutorial) as! RenderNode
2424
let indexingRecords = try renderNode.indexingRecords(onPage: tutorialReference)
2525
XCTAssertEqual(4, indexingRecords.count)
@@ -93,7 +93,7 @@ class IndexingTests: XCTestCase {
9393
let articleReference = ResolvedTopicReference(bundleIdentifier: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)
9494
let node = try context.entity(with: articleReference)
9595
let article = node.semantic as! TutorialArticle
96-
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference, source: context.documentURL(for: articleReference))
96+
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference)
9797
let renderNode = converter.visit(article) as! RenderNode
9898
let indexingRecords = try renderNode.indexingRecords(onPage: articleReference)
9999

@@ -191,7 +191,7 @@ class IndexingTests: XCTestCase {
191191
let articleReference = ResolvedTopicReference(bundleIdentifier: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)
192192
let node = try context.entity(with: articleReference)
193193
let article = node.semantic as! Symbol
194-
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference, source: context.documentURL(for: articleReference))
194+
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference)
195195
let renderNode = converter.visit(article) as! RenderNode
196196
let indexingRecords = try renderNode.indexingRecords(onPage: articleReference)
197197

@@ -224,7 +224,7 @@ class IndexingTests: XCTestCase {
224224
let articleReference = ResolvedTopicReference(bundleIdentifier: "org.swift.docc.example", path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift)
225225
let node = try context.entity(with: articleReference)
226226
let article = node.semantic as! Symbol
227-
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference, source: context.documentURL(for: articleReference))
227+
var converter = RenderNodeTranslator(context: context, bundle: bundle, identifier: articleReference)
228228
let renderNode = converter.visit(article) as! RenderNode
229229
let indexingRecords = try renderNode.indexingRecords(onPage: articleReference)
230230

0 commit comments

Comments
 (0)