Skip to content

Commit

Permalink
Support @DeprecationSummary in doc comments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
franklinsch committed Dec 11, 2024
1 parent d1622c6 commit 7e9579a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions Sources/SwiftDocC/Model/DocumentationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ public struct DocumentationNode {

private let directivesSupportedInDocumentationComments = [
Metadata.directiveName,
DeprecationSummary.directiveName,
]
// Renderable directives are processed like any other piece of structured markdown (tables, lists, etc.)
// and so are inherently supported in doc comments.
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftDocC/Semantics/Symbol/DeprecationSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import Markdown
/// }
/// ```
///
/// You can use the `@DeprecationSummary` directive top-level in both articles and documentation extension files.
/// You can use the `@DeprecationSummary` directive top-level in articles, documentation extension files, or documentation comments.
///
/// > Earlier versions: Before Swift-DocC 6.1, `@DeprecationSummary` was not supported in documentation comments.
///
/// > Tip:
/// > If you are writing a custom deprecation summary message for an API or documentation page that isn't already deprecated,
Expand Down
8 changes: 7 additions & 1 deletion Sources/docc/DocCDocumentation.docc/DocC.symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,13 @@
"text" : ""
},
{
"text" : "You can use the `@DeprecationSummary` directive top-level in both articles and documentation extension files."
"text" : "You can use the `@DeprecationSummary` directive top-level in articles, documentation extension files, or documentation comments."
},
{
"text" : ""
},
{
"text" : "> Earlier versions: Before Swift-DocC 6.1, `@DeprecationSummary` was not supported in documentation comments."
},
{
"text" : ""
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftDocCTests/Semantics/SymbolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,32 @@ class SymbolTests: XCTestCase {
)
}

func testParsesDeprecationSummaryDirectiveFromDocComment() throws {
let (node, problems) = try makeDocumentationNodeForSymbol(
docComment: """
The symbol's abstract.
@DeprecationSummary {
This is the deprecation summary.
}
""",
articleContent: nil
)

XCTAssert(problems.isEmpty)

XCTAssertEqual(
(node.semantic as? Symbol)?
.deprecatedSummary?
.content
.first?
.format()
.trimmingCharacters(in: .whitespaces)
,
"This is the deprecation summary."
)
}

// MARK: - Helpers

func makeDocumentationNodeForSymbol(
Expand Down

0 comments on commit 7e9579a

Please sign in to comment.