-
Notifications
You must be signed in to change notification settings - Fork 146
R117883810 @redirected placement #805
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
R117883810 @redirected placement #805
Conversation
while parsing titles, abstracts and discussions, allowing them to appear anywhere after the title.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me.
Since it's a user facing enhancements it would be nice to document that @Redirected
is supported in @Metadata
as of 5.11.
I don't remember if running swift run generate-symbol-graph
is sufficient to list @Redirected
is a supported directive inside of @Metadata
, since both directives are AutomaticDirectiveConvertible
. Regardless, we should probably mention in a note that it's only available in 5.11 and later (otherwise it will look like it's been supported since 5.5 (since both directives are marked as being introduced then)
Metadata.directiveName, | ||
Options.directiveName, | ||
Redirect.directiveName, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe that we should also add DeprecationSummary
to this list (see rdar://79719308)—but that could fit better in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure sounds good. I can take that Radar.
func checkSectionContent(expectedContent: String?, section: Section?) { | ||
if let desc = section?.content.map({ $0.detachedFromParent.debugDescription() }).joined(separator: "\n") { | ||
XCTAssertEqual(expectedContent, desc, "Found unexpected content: \n\(desc)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When adding test helpers like this it's helpful to given them file
and line
arguments that default to #file
and #line
and then also pass those values to all the XCTAssert
calls. This makes it so that if the test fails then the failure will be attributed to the location that called checkSectionContent
instead of the location inside of that function. It barely matters if the test helper is local to the same file, but if it's a general test helper in a separate file it can make a big difference.
func checkSectionContent(expectedContent: String?, section: Section?) { | |
if let desc = section?.content.map({ $0.detachedFromParent.debugDescription() }).joined(separator: "\n") { | |
XCTAssertEqual(expectedContent, desc, "Found unexpected content: \n\(desc)") | |
func checkSectionContent(expectedContent: String?, section: Section?, file: StaticString = #file, line: UInt = #line) { | |
if let desc = section?.content.map({ $0.detachedFromParent.debugDescription() }).joined(separator: "\n") { | |
XCTAssertEqual(expectedContent, desc, "Found unexpected content: \n\(desc)", file: file, line: line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks great suggestion 👍 Updated.
@@ -87,6 +90,7 @@ public final class Metadata: Semantic, AutomaticDirectiveConvertible { | |||
"supportedLanguages" : \Metadata._supportedLanguages, | |||
"_pageColor" : \Metadata.__pageColor, | |||
"titleHeading" : \Metadata._titleHeading, | |||
"redirects" : \Metadata._redirects, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the super nit but the misalignment bugged me
"redirects" : \Metadata._redirects, | |
"redirects" : \Metadata._redirects, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha ha no problem - updated
@@ -146,7 +154,7 @@ struct DocumentationMarkup { | |||
// Found deprecation notice in the abstract. | |||
deprecation = MarkupContainer(directive.children) | |||
return | |||
} else if directive.name == Comment.directiveName || directive.name == Metadata.directiveName || directive.name == Options.directiveName { | |||
} else if Self.directivesRemovedFromContent.contains(directive.name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. That's more easier to expand to cover more directives in the future. 👍
@swift-ci please test |
@swift-ci please test |
Turns out that |
@swift-ci please test |
/// | ||
/// > Note: Starting with version 5.11, @Redirected is supported as a child directive of @Metadata. In | ||
/// previous versions, @Redirected must be used as a top level directive. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this 💗
static var hiddenFromDocumentation = true | ||
static var hiddenFromDocumentation = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patshaughnessy I'm not following here, why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the generate-symbol-graph
command to document all of DocC's directives automatically. This command generates a symbol graph file for these, which is then used when we compile and publish documentation for DocC itself. This particular setting is used here to filter out some directives. (I'm not sure why we need to filter them at all, to be honest). Since hiddenFromDocumentation
was set to true previously for @Redirected
, I changed it to false to include docs for this again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Pat!
Bug/issue #, if applicable: rdar://117883810
Summary
Today DocC does not parse the
@Redirected
directive properly if it appears before the abstract in an article or documentation extension. If the directive appears before the abstract, the abstract's contents is set to the directive only and the actual abstract is instead considered to be part of the following discussion.For example, compiling this article:
...would produce this page:
Note the abstract appears under "Overview", and that there are two "Overview" sections.
This fix removes any
@Redirected
directives from markdown content while parsing the title, abstract and discussion. Now DocC no longer considers@Redirected
directives to be part of the markdown content at all, similar to how@Comment
,@Metadata
and@Options
work. DocC saves the redirects' old path strings behind the scenes.A related fix in this PR adds
@Redirected
as a child directive of@Metadata
. This gives the author more flexibility to place@Redirected
commands anywhere, including inside of the page's metadata which is the most logical place for it to appear.Dependencies
None.
Testing
Repeat the same test, but move the
@Redirected
directive inside the@Metadata
directives as a child. For example:The page should render correctly again.
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeededUpdated documentation if necessary