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

Compute beta platform information for non-symbol documentation #959

Merged
merged 17 commits into from
Jul 4, 2024

Commits on Jun 27, 2024

  1. Use VersionTriplet for @Available directive

    Changes:
    - `@Available` directive now parses `introduced` field as a `VersionTriplet`
    - `.stringRepresentation(precisionUpToNonsignificant:)` has been moved to `VersionTriplet`
    - Modifies tests so that they compile given the above changes
    
    The availability directive supports an "introduced" field, which accepted any string. This commit modifies it to only accept strings which can be converted into a VersionTriplet, the type which DocC uses internally for representing version information.
    
    This is useful to be able to compare the availability from the `@Availability` directive with the platform metadata which DocC's context contains, for purposes such as determining whether a platform has been configured as being in beta.
    
    The `.stringRepresentation(precisionUpToNonsignificant:)` functionality has been moved to `VersionTriplet`, which is a non-breaking change as this was internal API.  This is because we don't always have a `SymbolGraph.SemanticVersion` as the starting type, for example when using the `@Available` directive.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    8d82441 View commit details
    Browse the repository at this point in the history
  2. Compute platform beta status when using @Available

    Changes:
    - Sets `AvailabilityRenderItem.isBeta` when `AvailabilityRenderItem.init?(_ :current:)` is called
    - Makes `AvailabilityRenderItem.isBeta`, `AvailabilityRenderItem. introduced` and `AvailabilityRenderItem.name`  into `let` properties as they are integral to availability rendering.
    
    Unifies the behavior in `AvailabilityRenderItem` so that we always compute whether a platform is in beta, regardless of whether the availability information comes from the symbol graph or comes from the `@Available` directive.
    
    This fixes an issue where sample code articles defined with `@Available` directives would never display a beta badge regardless of whether the platform was configured to be a beta platform.
    
    Additionally, makes `isBeta` a `let` property to avoid any future bugs, as the code will now no longer compile unless this property is set in an initializer.
    
    Resolves rdar://129355087.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    4361d8d View commit details
    Browse the repository at this point in the history
  3. Adds documentation for new @Available behavior

    Documents the format which is expected for the "introduced" field of the `@Available` directive.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    7b5d185 View commit details
    Browse the repository at this point in the history
  4. Remove the source-breaking change to Metadata.Availability

    Reintroduces `Metadata.Availability.introduced` as a `String` to avoid any API breaking changes. Deprecates this field, in preparation for removal in a future release. Values for this field are derived from `Metadata.Availability.introducedVersion`.
    
    `Metadata.Availability.introducedVersion` is now driving argument `introduced` of the directive.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    568318e View commit details
    Browse the repository at this point in the history
  5. Add unit tests for new @Available behaviour

    - Adds unit tests for verifying that the `introduced` field is parsed with the correct formatting rules.
    - Fixes a bug where a leading or trailing full stop would be considered a valid format.
    - Updates FIXMEs to contain the most up-to-date information
    - Refactors MetadataAvailabilityTests slightly
    
    Resolves rdar://129355087.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    7e7a54e View commit details
    Browse the repository at this point in the history
  6. Add unit tests to PlatformAvailabilityTests for beta availability

    - Adds tests to verify that availability defined only in articles is correctly detected as beta depending on configuration.
    
    Resolves rdar://129355087.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    568e286 View commit details
    Browse the repository at this point in the history
  7. Add diagnostic explanation for non-convertible directive arguments

    When a directive argument is not convertible to a complex type (such as VersionTriplet), it is complicated for the author to know what the valid format is.
    
    Added a field `expectedFormat` in various places which can be used to specify a string which will describe what the expected format is.
    
    The changes are all non-breaking because they are either additive or they modify internal API.
    
    Added a custom expected format for `VersionTriplet` to improve the diagnostic information.
    
    Resolves rdar://129355087.
    anferbui committed Jun 27, 2024
    Configuration menu
    Copy the full SHA
    f5f320b View commit details
    Browse the repository at this point in the history

Commits on Jun 28, 2024

  1. Revert change to make isBeta a let property

    This is a source-breaking change, so removing it.
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    5858ded View commit details
    Browse the repository at this point in the history
  2. Use if-expression to declare variables

    Assignments can be written succinctly using an if-expression as of Swift 5.9 (https://github.com/swiftlang/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md)
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    8da7bff View commit details
    Browse the repository at this point in the history
  3. Make assertions in PlatformAvailabilityTests clearer

    Makes the test assertions clearer by rephrasing the logic. These assertions are tricky to read because `isBeta` can be one of three values: true, false and nil.
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    d26b467 View commit details
    Browse the repository at this point in the history
  4. Make AvailabilityRenderItem.isBeta(introduced:current:) private

    The function is only used in this file, and not needed anywhere else. We can leave it private.
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    89eb015 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d67cc9f View commit details
    Browse the repository at this point in the history
  6. Move to using SemanticVersion

    Uses `SemanticVersion` type rather than `VersionTriplet`. We have 4 types in DocC to represent a semantic version, and want to converge towards using only SemanticVersion:
    swiftlang#970
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    7efe5c1 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    8223994 View commit details
    Browse the repository at this point in the history
  8. Merge "deprecated" parameter changes with SemanticVersion changes

    Unifies the "deprecated" parameter behavior with the new "introduced" parameter behaviour, by making both of them be a `SemanticVersion` type.
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    7d729c0 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    98f9308 View commit details
    Browse the repository at this point in the history
  10. Update @Available documentation

    Updates to mention that the `deprecated` argument is also meant to be a semantic version.
    anferbui committed Jun 28, 2024
    Configuration menu
    Copy the full SHA
    1bfe9b4 View commit details
    Browse the repository at this point in the history