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

Adding deprecated to @Available directive #851

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ public struct AvailabilityRenderItem: Codable, Hashable, Equatable {

init?(_ availability: Metadata.Availability, current: PlatformVersion?) {
// FIXME: Deprecated/Beta markings need platform versions to display properly in Swift-DocC-Render (rdar://56897597)
// Fill in the appropriate values here when that's fixed (https://github.com/apple/swift-docc/issues/441)

let platformName = PlatformName(metadataPlatform: availability.platform)
name = platformName?.displayName
introduced = availability.introduced
deprecated = availability.deprecated
}

/// Creates a new item with the given platform name and version string.
Expand Down
21 changes: 9 additions & 12 deletions Sources/SwiftDocC/Semantics/Metadata/Availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ extension Metadata {
///
/// `@Available` is analogous to the `@available` attribute in Swift: It allows you to specify a
/// platform version that the page relates to. To specify a platform and version, list the platform
/// name and use the `introduced` argument:
/// name and use the `introduced` argument. In addition, you can also specify a deprecated
/// version, using the `deprecated` argument:
///
/// ```markdown
/// @Available(macOS, introduced: "12.0")
/// @Available(macOS, introduced: "12.0", deprecated: "14.0")
/// ```
///
/// Any text can be given to the first argument, and will be displayed in the page's
Expand Down Expand Up @@ -48,8 +50,6 @@ extension Metadata {
public static let introducedVersion = "5.8"

public enum Platform: RawRepresentable, Hashable, DirectiveArgumentValueConvertible {
// FIXME: re-add `case any = "*"` when `isBeta` and `isDeprecated` are implemented
// cf. https://github.com/apple/swift-docc/issues/441
case macOS, iOS, watchOS, tvOS

case other(String)
Expand All @@ -63,12 +63,7 @@ extension Metadata {
return
}
}
if rawValue == "*" {
// Reserve the `*` platform for when `isBeta` and `isDeprecated` can be implemented
return nil
} else {
self = .other(rawValue)
}
self = .other(rawValue)
}

public var rawValue: String {
Expand All @@ -90,16 +85,18 @@ extension Metadata {
@DirectiveArgumentWrapped(name: .unnamed)
public var platform: Platform

/// The platform version that this page applies to.
/// The platform version that this page was introduced in..
@DirectiveArgumentWrapped
public var introduced: String

// FIXME: `isBeta` and `isDeprecated` properties/arguments
// cf. https://github.com/apple/swift-docc/issues/441
/// The platform version that this page was deprecated in.
@DirectiveArgumentWrapped
public var deprecated: String? = nil

static var keyPaths: [String : AnyKeyPath] = [
"platform" : \Availability._platform,
"introduced" : \Availability._introduced,
"deprecated" : \Availability._deprecated,
]

public let originalMarkup: Markdown.BlockDirective
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftDocC/Semantics/Symbol/PlatformName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public struct PlatformName: Codable, Hashable, Equatable {
///
/// Returns `nil` if the given platform was ``Metadata/Availability/Platform/any``.
init?(metadataPlatform platform: Metadata.Availability.Platform) {
// Note: This is still an optional initializer to prevent source breakage when
// `Availability.Platform` re-introduces the `.any` case
// cf. https://github.com/apple/swift-docc/issues/441
if let knowDomain = Self.platformNamesIndex[platform.rawValue.lowercased()] {
self = knowDomain
} else {
Expand Down
16 changes: 6 additions & 10 deletions Tests/SwiftDocCTests/Semantics/MetadataAvailabilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ class MetadataAvailabilityTests: XCTestCase {
func testValidDirective() throws {
// assemble all the combinations of arguments you could give
let validArguments: [String] = [
// FIXME: isBeta and isDeprecated are unused (https://github.com/apple/swift-docc/issues/441)
// "isBeta: true",
// "isDeprecated: true",
// "isBeta: true, isDeprecated: true",
"deprecated: \"0.1\"",
]
// separate those that give a version so we can test the `*` platform separately
var validArgumentsWithVersion = ["introduced: \"1.0\""]
Expand All @@ -76,10 +73,9 @@ class MetadataAvailabilityTests: XCTestCase {

var checkPlatforms = Metadata.Availability.Platform.defaultCases.map({ $0.rawValue })
checkPlatforms.append("Package")
checkPlatforms.append("*")

for platform in checkPlatforms {
// FIXME: Test validArguments with the `*` platform once that's introduced
// cf. https://github.com/apple/swift-docc/issues/441
for args in validArgumentsWithVersion {
try assertValidAvailability(source: "@Available(\(platform), \(args))")
}
Expand All @@ -91,16 +87,16 @@ class MetadataAvailabilityTests: XCTestCase {
}

// also test for giving no platform
for args in validArguments {
try assertValidAvailability(source: "@Available(\(args))")
for args in validArgumentsWithVersion {
try assertValidAvailability(source: "@Available(*, \(args))")
}

// basic validity test for giving several directives
// FIXME: re-add isBeta after that is implemented (https://github.com/apple/swift-docc/issues/441)
let source = """
@Metadata {
@Available(macOS, introduced: "11.0")
@Available(iOS, introduced: "15.0")
@Available(watchOS, introduced: "7.0", deprecated: "9.0")
@Available("My Package", introduced: "0.1", deprecated: "1.0")
}
"""
try assertValidMetadata(source: source)
Expand Down