Skip to content

Commit 42c7ba9

Browse files
authored
Check the module name to know when to skip inherited doc comments. (#314)
* Check the module name to know when to skip inherited doc comments. * Fallback to the previous logic when the new doc comment info is missing * Use new function in SymbolKit that handles older symbol graph versions * Use merged version of SymbolKit changes
1 parent aebc226 commit 42c7ba9

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
11791179
edge: relationship,
11801180
context: self,
11811181
symbolIndex: &symbolIndex,
1182+
moduleName: moduleName,
11821183
engine: diagnosticEngine
11831184
)
11841185
}

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphRelationshipsBuilder.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ struct SymbolGraphRelationshipsBuilder {
336336
/// - selector: The symbol graph selector in which the relationship is relevant.
337337
/// - context: A documentation context.
338338
/// - symbolIndex: A symbol lookup map by precise identifier.
339+
/// - moduleName: The symbol name of the current module.
339340
/// - engine: A diagnostic collecting engine.
340341
static func addInheritedDefaultImplementation(
341342
edge: SymbolGraph.Relationship,
342-
context: DocumentationContext, symbolIndex:
343-
inout [String: DocumentationNode], engine:
344-
DiagnosticEngine
343+
context: DocumentationContext,
344+
symbolIndex: inout [String: DocumentationNode],
345+
moduleName: String,
346+
engine: DiagnosticEngine
345347
) {
346348
func setAsInheritedSymbol(origin: SymbolGraph.Relationship.SourceOrigin, for node: inout DocumentationNode, originNode: DocumentationNode?) {
347349
(node.semantic as! Symbol).origin = origin
@@ -358,7 +360,7 @@ struct SymbolGraphRelationshipsBuilder {
358360
// Remove any inherited docs from the original symbol if the feature is disabled.
359361
// However, when the docs are inherited from within the same module, its content can be resolved in
360362
// the local context, so keeping those inherited docs provide a better user experience.
361-
if !context.externalMetadata.inheritDocs && node.unifiedSymbol?.documentedSymbol?.isDocCommentFromSameModule == false {
363+
if !context.externalMetadata.inheritDocs && node.unifiedSymbol?.documentedSymbol?.isDocCommentFromSameModule(symbolModuleName: moduleName) == false {
362364
node.unifiedSymbol?.docComment.removeAll()
363365
}
364366
}

Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,40 @@ Document @1:1-11:19
26412641
let expectedRenderedAbstract: [RenderInlineContent]
26422642
}
26432643
let testData = [
2644+
// With the new module information
2645+
TestData(
2646+
docCommentJSON: """
2647+
{
2648+
"lines": [{
2649+
"text": "Authored abstract",
2650+
"range": {
2651+
"start": {"line": 1, "character": 4},
2652+
"end": {"line": 1, "character": 21}
2653+
}
2654+
}],
2655+
"module": "SideKit",
2656+
"uri": "file://path/to/file.swift"
2657+
}
2658+
""",
2659+
expectedRenderedAbstract: [.text("Authored abstract")]
2660+
),
2661+
TestData(
2662+
docCommentJSON: """
2663+
{
2664+
"lines": [{
2665+
"text": "Authored abstract",
2666+
"range": {
2667+
"start": {"line": 1, "character": 4},
2668+
"end": {"line": 1, "character": 21}
2669+
}
2670+
}],
2671+
"module": "OtherModule",
2672+
"uri": "file://path/to/file.swift"
2673+
}
2674+
""",
2675+
expectedRenderedAbstract: [.text("Inherited from "), .codeVoice(code: "Module.Protocol.inherited()"), .text(".")]
2676+
),
2677+
// Without the new module information
26442678
TestData(
26452679
docCommentJSON: """
26462680
{

0 commit comments

Comments
 (0)