Skip to content

Commit 7e9579a

Browse files
committed
Support @DeprecationSummary in doc comments
Adds support for authoring `@DeprecationSummary` messages in documentation comments. This is useful when you want to provide a formatted documentation summary for an API that's deprecated, but don't want to create a documentation extension file in order to do just that. It turns out that DocC already supported this, but emitted a warning whenever you did so. This commit removes that warning.
1 parent d1622c6 commit 7e9579a

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

Sources/SwiftDocC/Model/DocumentationNode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ public struct DocumentationNode {
849849

850850
private let directivesSupportedInDocumentationComments = [
851851
Metadata.directiveName,
852+
DeprecationSummary.directiveName,
852853
]
853854
// Renderable directives are processed like any other piece of structured markdown (tables, lists, etc.)
854855
// and so are inherently supported in doc comments.

Sources/SwiftDocC/Semantics/Symbol/DeprecationSummary.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import Markdown
2424
/// }
2525
/// ```
2626
///
27-
/// You can use the `@DeprecationSummary` directive top-level in both articles and documentation extension files.
27+
/// You can use the `@DeprecationSummary` directive top-level in articles, documentation extension files, or documentation comments.
28+
///
29+
/// > Earlier versions: Before Swift-DocC 6.1, `@DeprecationSummary` was not supported in documentation comments.
2830
///
2931
/// > Tip:
3032
/// > If you are writing a custom deprecation summary message for an API or documentation page that isn't already deprecated,

Sources/docc/DocCDocumentation.docc/DocC.symbols.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,13 @@
20332033
"text" : ""
20342034
},
20352035
{
2036-
"text" : "You can use the `@DeprecationSummary` directive top-level in both articles and documentation extension files."
2036+
"text" : "You can use the `@DeprecationSummary` directive top-level in articles, documentation extension files, or documentation comments."
2037+
},
2038+
{
2039+
"text" : ""
2040+
},
2041+
{
2042+
"text" : "> Earlier versions: Before Swift-DocC 6.1, `@DeprecationSummary` was not supported in documentation comments."
20372043
},
20382044
{
20392045
"text" : ""

Tests/SwiftDocCTests/Semantics/SymbolTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,32 @@ class SymbolTests: XCTestCase {
13131313
)
13141314
}
13151315

1316+
func testParsesDeprecationSummaryDirectiveFromDocComment() throws {
1317+
let (node, problems) = try makeDocumentationNodeForSymbol(
1318+
docComment: """
1319+
The symbol's abstract.
1320+
1321+
@DeprecationSummary {
1322+
This is the deprecation summary.
1323+
}
1324+
""",
1325+
articleContent: nil
1326+
)
1327+
1328+
XCTAssert(problems.isEmpty)
1329+
1330+
XCTAssertEqual(
1331+
(node.semantic as? Symbol)?
1332+
.deprecatedSummary?
1333+
.content
1334+
.first?
1335+
.format()
1336+
.trimmingCharacters(in: .whitespaces)
1337+
,
1338+
"This is the deprecation summary."
1339+
)
1340+
}
1341+
13161342
// MARK: - Helpers
13171343

13181344
func makeDocumentationNodeForSymbol(

0 commit comments

Comments
 (0)