Skip to content

Commit 8bf7925

Browse files
authored
Enable "mentioned in" feature by default (#1114)
* Enable "mentioned in" feature by default * Briefly document the "mentioned in" links feature
1 parent 8df2f65 commit 8bf7925

File tree

9 files changed

+64
-16
lines changed

9 files changed

+64
-16
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ public class DocumentationContext {
681681
for result in results.sync({ $0 }) {
682682
documentationCache[result.reference] = result.node
683683

684-
if FeatureFlags.current.isExperimentalMentionedInEnabled {
684+
if FeatureFlags.current.isMentionedInEnabled {
685685
// Record symbol links as symbol "mentions" for automatic cross references
686686
// on rendered symbol documentation.
687687
if let article = result.node.semantic as? Article,

Sources/SwiftDocC/Model/Rendering/RenderSectionTranslator/MentionsSectionTranslator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct MentionsSectionTranslator: RenderSectionTranslator {
1515
}
1616

1717
func translateSection(for symbol: Symbol, renderNode: inout RenderNode, renderNodeTranslator: inout RenderNodeTranslator) -> VariantCollection<CodableContentSection?>? {
18-
guard FeatureFlags.current.isExperimentalMentionedInEnabled else {
18+
guard FeatureFlags.current.isMentionedInEnabled else {
1919
return nil
2020
}
2121

Sources/SwiftDocC/Utility/FeatureFlags.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ public struct FeatureFlags: Codable {
2323
/// Whether or not experimental support for combining overloaded symbol pages is enabled.
2424
public var isExperimentalOverloadedSymbolPresentationEnabled = false
2525

26-
/// Whether experimental support for automatically rendering links on symbol documentation to articles
27-
/// that mention that symbol.
28-
public var isExperimentalMentionedInEnabled = false
26+
/// Whether support for automatically rendering links on symbol documentation to articles that mention that symbol is enabled.
27+
public var isMentionedInEnabled = true
28+
29+
@available(*, deprecated, renamed: "isMentionedInEnabled", message: "Use 'isMentionedInEnabled' instead. This deprecated API will be removed after 6.2 is released")
30+
public var isExperimentalMentionedInEnabled: Bool {
31+
get { isMentionedInEnabled }
32+
set { isMentionedInEnabled = newValue }
33+
}
2934

3035
/// Whether or not support for validating parameters and return value documentation is enabled.
3136
public var isParametersAndReturnsValidationEnabled = true

Sources/SwiftDocCUtilities/ArgumentParsing/ActionExtensions/ConvertAction+CommandInitialization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension ConvertAction {
2323
FeatureFlags.current.isExperimentalDeviceFrameSupportEnabled = convert.enableExperimentalDeviceFrameSupport
2424
FeatureFlags.current.isExperimentalLinkHierarchySerializationEnabled = convert.enableExperimentalLinkHierarchySerialization
2525
FeatureFlags.current.isExperimentalOverloadedSymbolPresentationEnabled = convert.enableExperimentalOverloadedSymbolPresentation
26-
FeatureFlags.current.isExperimentalMentionedInEnabled = convert.enableExperimentalMentionedIn
26+
FeatureFlags.current.isMentionedInEnabled = convert.enableMentionedIn
2727
FeatureFlags.current.isParametersAndReturnsValidationEnabled = convert.enableParametersAndReturnsValidation
2828

2929
// If the user-provided a URL for an external link resolver, attempt to

Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/Convert.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,17 @@ extension Docc {
503503
var enableExperimentalOverloadedSymbolPresentation = false
504504

505505
@Flag(
506-
name: .customLong("enable-experimental-mentioned-in"),
506+
name: .customLong("mentioned-in"),
507+
inversion: .prefixedEnableDisable,
507508
help: ArgumentHelp("Render a section on symbol documentation which links to articles that mention that symbol", discussion: """
508509
Validates and filters symbols' parameter and return value documentation based on the symbol's function signature in each language representation.
509510
""")
510511
)
512+
var enableMentionedIn = true
513+
514+
// This flag only exist to allow developers to pass the previous '--enable-experimental-...' flag without errors.
515+
@Flag(name: .customLong("enable-experimental-mentioned-in"), help: .hidden)
516+
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released")
511517
var enableExperimentalMentionedIn = false
512518

513519
@Flag(
@@ -536,6 +542,7 @@ extension Docc {
536542
Convert.warnAboutDeprecatedOptionIfNeeded("enable-experimental-json-index", message: "This flag has no effect. The JSON render is emitted by default.")
537543
Convert.warnAboutDeprecatedOptionIfNeeded("experimental-parse-doxygen-commands", message: "This flag has no effect. Doxygen support is enabled by default.")
538544
Convert.warnAboutDeprecatedOptionIfNeeded("enable-experimental-parameters-and-returns-validation", message: "This flag has no effect. Parameter and return value validation is enabled by default.")
545+
Convert.warnAboutDeprecatedOptionIfNeeded("enable-experimental-mentioned-in", message: "This flag has no effect. Automatic mentioned in sections is enabled by default.")
539546
Convert.warnAboutDeprecatedOptionIfNeeded("index", message: "Use '--emit-lmdb-index' indead.")
540547
emitLMDBIndex = emitLMDBIndex
541548
}
@@ -598,9 +605,14 @@ extension Docc {
598605

599606
/// A user-provided value that is true if the user enables experimental automatically generated "mentioned in"
600607
/// links on symbols.
608+
public var enableMentionedIn: Bool {
609+
get { featureFlags.enableMentionedIn }
610+
set { featureFlags.enableMentionedIn = newValue }
611+
}
612+
@available(*, deprecated, renamed: "enableMentionedIn", message: "Use 'enableMentionedIn' instead. This deprecated API will be removed after 6.2 is released")
601613
public var enableExperimentalMentionedIn: Bool {
602-
get { featureFlags.enableExperimentalMentionedIn }
603-
set { featureFlags.enableExperimentalMentionedIn = newValue }
614+
get { enableMentionedIn }
615+
set { enableMentionedIn = newValue }
604616
}
605617

606618
/// A user-provided value that is true if the user enables experimental validation for parameters and return value documentation.

Sources/docc/DocCDocumentation.docc/linking-to-symbols-and-other-content.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ DocC supports the following link types to enable navigation between pages:
1313
| Tutorial | Links to a tutorial in your documentation catalog.
1414
| Web | Links to an external URL.
1515

16+
When you link to a symbol from an article's content, DocC automatically creates a "mentioned in" link from mentioned symbol's page to the article that mentioned the symbol.
17+
These "mentioned in" links helps the reader find conceptual content that put a specific symbol in context or that describe how to accomplish some task using that symbol.
18+
19+
DocC only creates "mentioned in" links when an _article_ links to a symbol and only when that link appears in the article's _content_.
20+
Links in topic groups---that organize your documentation into a hierarchy of topics and subtopics---doesn't produce "mentioned in" links.
21+
For more information about topic groups, see <doc:adding-structure-to-your-documentation-pages>.
22+
23+
> Earlier Versions:
24+
> Before Swift-DocC 6.2, automatic "mentioned in" links require that you pass the `--enable-experimental-mentioned-in` command line flag to `docc`.
25+
> This flag is available as of Swift-DocC 6.0.
26+
1627
### Navigate to a Symbol
1728

1829
To add a link to a symbol in your module, wrap the symbol's name in a set of double backticks (\`\`):

Tests/SwiftDocCTests/Rendering/MentionsRenderSectionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MentionsRenderSectionTests: XCTestCase {
1616
/// Verify that the Mentioned In section is present when a symbol is mentioned,
1717
/// pointing to the correct article.
1818
func testMentionedInSectionFull() throws {
19-
enableFeatureFlag(\.isExperimentalMentionedInEnabled)
19+
enableFeatureFlag(\.isMentionedInEnabled)
2020
let (bundle, context) = try createMentionedInTestBundle()
2121
let identifier = ResolvedTopicReference(
2222
bundleID: bundle.id,
@@ -39,7 +39,7 @@ class MentionsRenderSectionTests: XCTestCase {
3939

4040
/// If there are no qualifying mentions of a symbol, the Mentioned In section should not appear.
4141
func testMentionedInSectionEmpty() throws {
42-
enableFeatureFlag(\.isExperimentalMentionedInEnabled)
42+
enableFeatureFlag(\.isMentionedInEnabled)
4343
let (bundle, context) = try createMentionedInTestBundle()
4444
let identifier = ResolvedTopicReference(
4545
bundleID: bundle.id,

Tests/SwiftDocCTests/Semantics/ArticleSymbolMentionsTests.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ class ArticleSymbolMentionsTests: XCTestCase {
3636
XCTAssertEqual(gottenArticle, article)
3737
}
3838

39-
/// If the `--enable-mentioned-in` flag is passed, symbol mentions in the test bundle's
40-
/// articles should be recorded.
4139
func testSymbolLinkCollectorEnabled() throws {
42-
enableFeatureFlag(\.isExperimentalMentionedInEnabled)
4340
let (bundle, context) = try createMentionedInTestBundle()
4441

4542
// The test bundle currently only has one article with symbol mentions
@@ -61,9 +58,14 @@ class ArticleSymbolMentionsTests: XCTestCase {
6158
XCTAssertEqual(mentioningArticle, gottenArticle)
6259
}
6360

64-
/// If the `--enable-experimental-mentioned-in` flag is not passed, symbol mentions in the test bundle's
65-
/// articles should not be recorded.
6661
func testSymbolLinkCollectorDisabled() throws {
62+
let currentFeatureFlags = FeatureFlags.current
63+
addTeardownBlock {
64+
FeatureFlags.current = currentFeatureFlags
65+
}
66+
FeatureFlags.current.isMentionedInEnabled = false
67+
68+
6769
let (bundle, context) = try createMentionedInTestBundle()
6870
XCTAssertTrue(context.articleSymbolMentions.mentions.isEmpty)
6971

Tests/SwiftDocCUtilitiesTests/ArgumentParsing/ConvertSubcommandTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,24 @@ class ConvertSubcommandTests: XCTestCase {
578578
let disabledFlagConvert = try Docc.Convert.parse(["--disable-parameters-and-returns-validation"])
579579
XCTAssertEqual(disabledFlagConvert.enableParametersAndReturnsValidation, false)
580580
}
581+
582+
func testMentionedFeatureFlag() throws {
583+
// The feature is enabled when no flag is passed.
584+
let noFlagConvert = try Docc.Convert.parse([])
585+
XCTAssertEqual(noFlagConvert.enableMentionedIn, true)
586+
587+
// It's allowed to pass the previous "--enable-experimental-..." flag.
588+
let oldFlagConvert = try Docc.Convert.parse(["--enable-experimental-mentioned-in"])
589+
XCTAssertEqual(oldFlagConvert.enableMentionedIn, true)
590+
591+
// It's allowed to pass the redundant "--enable-..." flag.
592+
let enabledFlagConvert = try Docc.Convert.parse(["--enable-mentioned-in"])
593+
XCTAssertEqual(enabledFlagConvert.enableMentionedIn, true)
594+
595+
// Passing the "--disable-..." flag turns of the feature.
596+
let disabledFlagConvert = try Docc.Convert.parse(["--disable-mentioned-in"])
597+
XCTAssertEqual(disabledFlagConvert.enableMentionedIn, false)
598+
}
581599

582600
// This test calls ``ConvertOptions.infoPlistFallbacks._unusedVersionForBackwardsCompatibility`` which is deprecated.
583601
// Deprecating the test silences the deprecation warning when running the tests. It doesn't skip the test.

0 commit comments

Comments
 (0)