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

[external-links] Display frameworks as beta only if all platforms are beta #938

Merged
merged 6 commits into from
Jun 13, 2024

Conversation

anferbui
Copy link
Contributor

@anferbui anferbui commented Jun 4, 2024

Bug/issue #, if applicable: rdar://128997995

Summary

Symbols can have an availability per platform (iOS, macOS, etc), each of which can be marked as "beta" by providing some metadata when invoking docc:

swift run docc preview preview TestPackage.docc --platform name=macOS,version=40.0.0,beta=true --platform name=iOS,version=50.0.0,beta=true --platform name=watchOS,version=60.0.0,beta=true
Screenshot 2024-06-04 at 16 02 34

A top-level badge is sometimes rendered for a symbol, depending on its platform availability.

Currently there is a mismatch in behaviour where:

Screenshot 2024-06-04 at 16 09 57 Screenshot 2024-06-04 at 16 09 37

This behaviour is inconsistent and can be confusing for documentation writers. This PR proposes unifying the behaviour so that a symbol is shown as beta if all of its available platforms are in beta.

Implementation

Changes the behaviour of external link resolution in OutOfProcessReferenceResolver to only display a framework to be in beta if all the platforms its supported in are in beta.

This makes it match the behaviour for internal link resolution, so that the behaviour is consistent whether you're linking to a symbol internally within a framework or externally from another framework.

Also modifies LinkDestinationSummary to keep both of the external symbol resolution code paths in sync with each other. Hopefully in the future we can unify and have the same code path for both, but right now the logic is duplicated (and equal).

Dependencies

N/A.

Testing

You can set up a link resolver locally which has beta platform information in order to verify this fix:
link-resolver.zip

Excerpt:

"platforms": [
    {
      "name": "macOS",
      "introducedAt": "40.0.0",
      "beta": true
    },
    {
      "introducedAt": "50.0.0",
      "beta": true,
      "name": "iOS"
    },
    {
      "introducedAt": "60.0.0",
      "beta": false,
      "name": "watchOS"
    }
  ]

TestPackage.zip

Steps:

  1. Download link-resolver and TestPackage.
  2. Render documentation locally:
DOCC_LINK_RESOLVER_EXECUTABLE=link-resolver swift run docc preview TestPackage.docc --platform name=macOS,version=40.0.0,beta=true --platform name=iOS,version=50.0.0,beta=true
  1. Verify that in http://localhost:8080/documentation/testpackage/betaclass, neither of the symbols mentioned have a top level badge that says the symbol is a beta symbol.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • [n/a] Updated documentation if necessary

Verification

Unit tests

Added unit tests for OutOfProcessReferenceResolver and ExternalPathHierarchyResolver since these changes affect both types of external link resolution.

Ran ./bin/test:

❯ ./bin/test
Building for debugging...
[122/122] Linking SwiftDocCPackageTests
Build complete! (7.75s)
[1685/1685] Testing SwiftDocCUtilitiesTests.DirectoryMonitorTests/testMonitorDoesNotTriggerUpdates
=> Checking for unacceptable language… okay.
=> Checking license headers… okay.
=> Validating scripts in bin subdirectory… okay.

Site rendering

Before After
Screenshot 2024-06-04 at 16 31 53 Screenshot 2024-06-04 at 16 31 13

Documentation

As far as I can tell, no changes to the documentation are needed.

@anferbui anferbui force-pushed the tweak-beta-resolution branch from a50e773 to 0cab664 Compare June 5, 2024 15:59
@anferbui anferbui marked this pull request as ready for review June 5, 2024 16:01
@anferbui
Copy link
Contributor Author

anferbui commented Jun 5, 2024

@swift-ci please test

@anferbui anferbui requested a review from d-ronnqvist June 5, 2024 16:01
Copy link
Contributor

@patshaughnessy patshaughnessy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - just wondering if this is the right time for a larger refactoring to avoid duplicating more code like this. Maybe we merge this and then take on the larger work in another PR?

@@ -182,6 +182,15 @@ private extension Sequence<DeclarationRenderSection.Token> {
// MARK: ExternalEntity

private extension LinkDestinationSummary {
/// A value that indicates whether this symbol is under development and likely to change.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're adding exactly the same code to both LinkDestinationSummary and OutOfProcessReferenceResolver.ResolvedInformation - would it be worth introducing a protocol?

Actually I just saw this comment:

    public struct ResolvedInformation: Codable {
        // This type is duplicating the information from LinkDestinationSummary with some minor differences.
        // Changes generally need to be made in both places. It would be good to replace this with LinkDestinationSummary.
        // FIXME: https://github.com/apple/swift-docc/issues/802

Is this a good time to take on this refactoring work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that comment was exactly my reasoning for duplicating the API as closely as possible, thanks for calling that out!

I'll look into refactoring the code to see how much of a code change it would be to unify the code paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to unify the code paths appears to be quite involved, I'll look into it further tomorrow but I think we should tackle that as a separate PR regardless.

Copy link
Contributor

@d-ronnqvist d-ronnqvist Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely for a separate PR. It's would both be quite involved and a bit of a risky change.
#802

anferbui added 3 commits June 12, 2024 17:01
Changes the behaviour of external link resolution in `OutOfProcessReferenceResolver` to only display a framework to be in beta if all the platforms its supported in are in beta.

This makes it match the behaviour for internal link resolution, so that the behaviour is consistent whether you're linking to a symbol internally within a framework or externally from another framework.

Resolves rdar://128997995.
Makes changes to `OutOfProcessReferenceResolver .ResolvedInformation` so that it can be replaced by `LinkDestinationSummary` at some point in the future. Both `OutOfProcessReferenceResolver .ResolvedInformation` and `LinkDestinationSummary` now contain information about whether the resolved external link points to a symbol in beta or not, using equivalent API.

This is an attempt at keeping both of the logics about whether an external symbol is in beta in sync with each other. Hopefully in the future we can unify and have the same code path for both, but right now the logic is duplicated (and equal).

Resolves rdar://128997995.
Adds a unit test which verifies that the logic for determining whether a symbol is in beta when using `ExternalPathHierarchyResolver` is as expected.

Resolves rdar://128997995.
@anferbui anferbui force-pushed the tweak-beta-resolution branch from 0cab664 to d25a051 Compare June 12, 2024 16:01
anferbui added 3 commits June 12, 2024 17:06
Test file `OutOfProcessReferenceResolverTests` had inconsistent and confusing formatting, particularly with how the type of `makeResolver` was being defined across multiple lines in a way inconsistent with the rest of the codebase.

`makeResolver` is now declared as a one-liner and fixes other minor formatting/spacing issues.
The file isn't needed, so removing it.
We want to avoid spreading the configure context parameter to the other test helpers, as we're slowly working to make the context not be configured after creation.

Instead, `ExternalPathHierarchyResolverTests` now calls the underlying `loadBundle(from:configureContext:)` directly,
@anferbui
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@d-ronnqvist d-ronnqvist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thank you

@anferbui anferbui merged commit b46c7b5 into swiftlang:main Jun 13, 2024
2 checks passed
@anferbui anferbui deleted the tweak-beta-resolution branch June 13, 2024 09:51
anferbui added a commit to anferbui/swift-docc that referenced this pull request Jun 13, 2024
… beta (swiftlang#938)

* Display frameworks as beta only if all platforms are beta

Changes the behaviour of external link resolution in `OutOfProcessReferenceResolver` to only display a framework to be in beta if all the platforms its supported in are in beta.

This makes it match the behaviour for internal link resolution, so that the behaviour is consistent whether you're linking to a symbol internally within a framework or externally from another framework.

* Refactor code to have same behaviour in both external link resolvers

Makes changes to `OutOfProcessReferenceResolver .ResolvedInformation` so that it can be replaced by `LinkDestinationSummary` at some point in the future. Both `OutOfProcessReferenceResolver .ResolvedInformation` and `LinkDestinationSummary` now contain information about whether the resolved external link points to a symbol in beta or not, using equivalent API.

This is an attempt at keeping both of the logics about whether an external symbol is in beta in sync with each other. Hopefully in the future we can unify and have the same code path for both, but right now the logic is duplicated (and equal).

* Add a test for beta logic in ExternalPathHierarchyResolver

Adds a unit test which verifies that the logic for determining whether a symbol is in beta when using `ExternalPathHierarchyResolver` is as expected.

* Fix formatting

Test file `OutOfProcessReferenceResolverTests` had inconsistent and confusing formatting, particularly with how the type of `makeResolver` was being defined across multiple lines in a way inconsistent with the rest of the codebase.

`makeResolver` is now declared as a one-liner and fixes other minor formatting/spacing issues.

* Remove noop Info.plist

The file isn't needed, so removing it.

* Remove changes to testBundleAndContext helpers

We want to avoid spreading the configure context parameter to the other test helpers, as we're slowly working to make the context not be configured after creation.

Instead, `ExternalPathHierarchyResolverTests` now calls the underlying `loadBundle(from:configureContext:)` directly.

---

Resolves rdar://128997995.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants