Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable "mentioned in" feature by default #1114

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public class DocumentationContext {
for result in results.sync({ $0 }) {
documentationCache[result.reference] = result.node

if FeatureFlags.current.isExperimentalMentionedInEnabled {
if FeatureFlags.current.isMentionedInEnabled {
// Record symbol links as symbol "mentions" for automatic cross references
// on rendered symbol documentation.
if let article = result.node.semantic as? Article,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct MentionsSectionTranslator: RenderSectionTranslator {
}

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

Expand Down
11 changes: 8 additions & 3 deletions Sources/SwiftDocC/Utility/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public struct FeatureFlags: Codable {
/// Whether or not experimental support for combining overloaded symbol pages is enabled.
public var isExperimentalOverloadedSymbolPresentationEnabled = false

/// Whether experimental support for automatically rendering links on symbol documentation to articles
/// that mention that symbol.
public var isExperimentalMentionedInEnabled = false
/// Whether support for automatically rendering links on symbol documentation to articles that mention that symbol is enabled.
public var isMentionedInEnabled = true

@available(*, deprecated, renamed: "isMentionedInEnabled", message: "Use 'isMentionedInEnabled' instead. This deprecated API will be removed after 6.2 is released")
public var isExperimentalMentionedInEnabled: Bool {
get { isMentionedInEnabled }
set { isMentionedInEnabled = newValue }
}

/// Whether or not support for validating parameters and return value documentation is enabled.
public var isParametersAndReturnsValidationEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension ConvertAction {
FeatureFlags.current.isExperimentalDeviceFrameSupportEnabled = convert.enableExperimentalDeviceFrameSupport
FeatureFlags.current.isExperimentalLinkHierarchySerializationEnabled = convert.enableExperimentalLinkHierarchySerialization
FeatureFlags.current.isExperimentalOverloadedSymbolPresentationEnabled = convert.enableExperimentalOverloadedSymbolPresentation
FeatureFlags.current.isExperimentalMentionedInEnabled = convert.enableExperimentalMentionedIn
FeatureFlags.current.isMentionedInEnabled = convert.enableMentionedIn
FeatureFlags.current.isParametersAndReturnsValidationEnabled = convert.enableParametersAndReturnsValidation

// If the user-provided a URL for an external link resolver, attempt to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,17 @@ extension Docc {
var enableExperimentalOverloadedSymbolPresentation = false

@Flag(
name: .customLong("enable-experimental-mentioned-in"),
name: .customLong("mentioned-in"),
inversion: .prefixedEnableDisable,
help: ArgumentHelp("Render a section on symbol documentation which links to articles that mention that symbol", discussion: """
Validates and filters symbols' parameter and return value documentation based on the symbol's function signature in each language representation.
""")
)
var enableMentionedIn = true

// This flag only exist to allow developers to pass the previous '--enable-experimental-...' flag without errors.
@Flag(name: .customLong("enable-experimental-mentioned-in"), help: .hidden)
@available(*, deprecated, message: "This deprecated API will be removed after 6.2 is released")
var enableExperimentalMentionedIn = false

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

/// A user-provided value that is true if the user enables experimental automatically generated "mentioned in"
/// links on symbols.
public var enableMentionedIn: Bool {
get { featureFlags.enableMentionedIn }
set { featureFlags.enableMentionedIn = newValue }
}
@available(*, deprecated, renamed: "enableMentionedIn", message: "Use 'enableMentionedIn' instead. This deprecated API will be removed after 6.2 is released")
public var enableExperimentalMentionedIn: Bool {
get { featureFlags.enableExperimentalMentionedIn }
set { featureFlags.enableExperimentalMentionedIn = newValue }
get { enableMentionedIn }
set { enableMentionedIn = newValue }
}

/// A user-provided value that is true if the user enables experimental validation for parameters and return value documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MentionsRenderSectionTests: XCTestCase {
/// Verify that the Mentioned In section is present when a symbol is mentioned,
/// pointing to the correct article.
func testMentionedInSectionFull() throws {
enableFeatureFlag(\.isExperimentalMentionedInEnabled)
enableFeatureFlag(\.isMentionedInEnabled)
let (bundle, context) = try createMentionedInTestBundle()
let identifier = ResolvedTopicReference(
bundleID: bundle.id,
Expand All @@ -39,7 +39,7 @@ class MentionsRenderSectionTests: XCTestCase {

/// If there are no qualifying mentions of a symbol, the Mentioned In section should not appear.
func testMentionedInSectionEmpty() throws {
enableFeatureFlag(\.isExperimentalMentionedInEnabled)
enableFeatureFlag(\.isMentionedInEnabled)
let (bundle, context) = try createMentionedInTestBundle()
let identifier = ResolvedTopicReference(
bundleID: bundle.id,
Expand Down
12 changes: 7 additions & 5 deletions Tests/SwiftDocCTests/Semantics/ArticleSymbolMentionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class ArticleSymbolMentionsTests: XCTestCase {
XCTAssertEqual(gottenArticle, article)
}

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

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

/// If the `--enable-experimental-mentioned-in` flag is not passed, symbol mentions in the test bundle's
/// articles should not be recorded.
func testSymbolLinkCollectorDisabled() throws {
let currentFeatureFlags = FeatureFlags.current
addTeardownBlock {
FeatureFlags.current = currentFeatureFlags
}
FeatureFlags.current.isMentionedInEnabled = false


let (bundle, context) = try createMentionedInTestBundle()
XCTAssertTrue(context.articleSymbolMentions.mentions.isEmpty)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,24 @@ class ConvertSubcommandTests: XCTestCase {
let disabledFlagConvert = try Docc.Convert.parse(["--disable-parameters-and-returns-validation"])
XCTAssertEqual(disabledFlagConvert.enableParametersAndReturnsValidation, false)
}

func testMentionedFeatureFlag() throws {
// The feature is enabled when no flag is passed.
let noFlagConvert = try Docc.Convert.parse([])
XCTAssertEqual(noFlagConvert.enableMentionedIn, true)

// It's allowed to pass the previous "--enable-experimental-..." flag.
let oldFlagConvert = try Docc.Convert.parse(["--enable-experimental-mentioned-in"])
XCTAssertEqual(oldFlagConvert.enableMentionedIn, true)

// It's allowed to pass the redundant "--enable-..." flag.
let enabledFlagConvert = try Docc.Convert.parse(["--enable-mentioned-in"])
XCTAssertEqual(enabledFlagConvert.enableMentionedIn, true)

// Passing the "--disable-..." flag turns of the feature.
let disabledFlagConvert = try Docc.Convert.parse(["--disable-mentioned-in"])
XCTAssertEqual(disabledFlagConvert.enableMentionedIn, false)
}

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