-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add support for variant overrides in Render JSON #11
Merged
franklinsch
merged 2 commits into
swiftlang:main
from
franklinsch:render-json-variant-overrides
Oct 21, 2021
Merged
Add support for variant overrides in Render JSON #11
franklinsch
merged 2 commits into
swiftlang:main
from
franklinsch:render-json-variant-overrides
Oct 21, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds infrastructure support for adding language-specific overrides in Render JSON. Also, adds support specifying language variants for `RenderMetadata.title` and `TopicRenderReference.title`. rdar://82919099
@swift-ci test |
@swift-ci test |
@swift-ci test macOS |
@franklinsch should the Render JSON spec be updated with details about the new |
Great point @mportiz08, I filed https://bugs.swift.org/browse/SR-15354 to track this. |
@swift-ci test macOS |
ethan-kusters
approved these changes
Oct 20, 2021
@swift-ci test macOS |
3 tasks
franklinsch
added a commit
to franklinsch/swift-docc
that referenced
this pull request
Oct 29, 2021
Update the render JSON spec for the changes introduced in swiftlang#11. SR-15354 rdar://82919099
2 tasks
franklinsch
added a commit
to franklinsch/swift-docc
that referenced
this pull request
Oct 29, 2021
Update the render JSON spec for the changes introduced in swiftlang#11. SR-15354 rdar://83667105
franklinsch
added a commit
that referenced
this pull request
Nov 1, 2021
Update the render JSON spec for the changes introduced in #11. SR-15354 rdar://83667105
This was referenced Nov 18, 2021
3 tasks
This was referenced May 3, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug/issue #, if applicable: rdar://82919099
Summary
Adds infrastructure groundwork for adding language-specific overrides in the Render JSON model. This is in support of handling symbols that are available in multiple languages (like Swift+Objective-C symbols). More details here: https://forums.swift.org/t/extending-swift-docc-render-json-to-support-multi-language-symbols/52881
This PR also adds support for specifying language variants for
RenderMetadata.title
andTopicRenderReference.title
as an example for the new infrastructure.Example usage
As an example on how to make a property support language-specific variants, let's look at the change for
RenderMetadata.title
.We create a sibling
titleVariants
property that holds the default title (e.g., the Swift title) of the symbol, andupdate
title
to be a computed property that fetches/updates the default value oftitleVariants
.We update the encoder method of
RenderMetadata
to encode thetitleVariants
instead oftitle
, andVariantCollection<_>
's Codable implementation will encode the default value attitle
. It also accumulates thevariants and the JSON pointers they apply to to a dictionary, and that dictionary gets written to the
variantsOverride
property of the render node.
Then, to specify a variant for Objective-C documentation:
Implementation overview
At a high-level, properties in Render JSON models that can hold different values for different languages are now represented by a
VariantCollection<_>
value. When aVariantCollection<_>
value is encoded, two things happen:defaultValue
gets encoded into the encoder's containeruserInfo[.variantOverrides]
property.The
RenderNode
's Encodable implementation then grabs the encoder'suserInfo[.variantOverrides]
—which, at this point in the encoding process, contains the variants for all the variant collection values in the render node tree—and encodes the variants in the top-levelvariantOverrides
property. Clients can get aJSONEncoder
that's configured to accumulate variants information by using theRenderJSONEncoder.makeEncoder()
API.As a side-note, we updated the existing infrastructure to optimize the encoding of
references
objects across render node compilations to no longer cache encoded render references in theJSONEncoder
'suserInfo
, but instead in a cache passed as a parameter toRenderNode.encodeToJSON(with:renderReferenceCache:)
. This is because the new infrastructure relies on using separateJSONEncoder
instances for each render node compilation.Performance impact
Dependencies
None.
Testing
These changes are non-breaking, so there should be no user-facing changes (including in Render JSON).
To test the the
variantsOverrides
functionality:node.metadata.titleVariants
for example:Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded