-
Notifications
You must be signed in to change notification settings - Fork 158
Add experimental command to write generated curation to documentation extension files #597
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 experimental command to write generated curation to documentation extension files #597
Conversation
Also, add experimental flag to in-place add generated curation during a convert action for easier integration with build workflows. rdar://98528457
8b69ffc
to
e168e96
Compare
❤️ |
Yes, without IDE integration there isn't a great way to get to this information today. I'm not sure if this is the best way to surface this information but I think it's a decent start that we can evolve as more people use it and provide feedback on it. Inspecting the linkable entities is a decent workaround but it's has some drawbacks since the path to a page has more restrictions than the link to a page. For example, |
# Conflicts: # Sources/SwiftDocCUtilities/Docc.swift
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
# Conflicts: # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift # Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/Convert.swift # Sources/SwiftDocCUtilities/Docc.swift
0597991
to
598f2cd
Compare
This comment was marked as resolved.
This comment was marked as resolved.
# Conflicts: # Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/Convert.swift
c54a849
to
f6168ad
Compare
This comment was marked as resolved.
This comment was marked as resolved.
@swift-ci please test |
@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.
This is incredibly useful, thank you for adding this! I've been using this command and one thing I've noticed is that if symbols don't have children, it doesn't emit a documentation extension, which given the name emit-generation-curation
, is correct behaviour since there's no curation to generate for pages with no children.
Do you see value in bringing support for generating documentation extensions for symbols that don't have children though? A command such as docc process-catalog generate-documentation-extension --symbol "Foo/Bar"
could work well for this. This isn't the focus of your PR though, so it would make sense to address this as part of future work, unless you think the feature you're contributing here is incompatible with the command I'm suggesting above (which I don't think it is).
In the meantime, I wonder if we should make the help text of emit-generated-curation
clearer. It's currently:
Write documentation extension files into the DocC Catalog.
but there could benefit in clarifying that the purpose of this is generating curation, and hence symbols with no children don't get an extension generated.
Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/EmitGeneratedCuration.swift
Outdated
Show resolved
Hide resolved
@swift-ci please test |
Yes, the intended behavior is that DocC will only write a file if there's any autogenerated curation in it.
We could add functionality like that in a separate command. I intentionally made this a subcommand of a new On its own I don't feel like a command to only generate documentation files is very useful. To do it for a specific symbol you already need to write the symbol link for that symbol and to generate large numbers of empty extension files is a bit of an uncommon use case. That said, it's probably very easy to implement if someone has a need for it and wants to contribute a catalog processing subcommand. Maybe there are more specific use cases where DocC can automate more of the work? For example, overriding a symbol in a documentation extension where DocC could insert the directive to configure the override behavior and copy over the in-source documentation for that symbol as a starting point.
I updated this to "Write documentation extension files with markdown representations of DocC's automatic curation." and also added a brief discussion section with some information for people who are new to this command and/or new to curation in DocC:
|
# Conflicts: # Sources/SwiftDocCUtilities/ArgumentParsing/Subcommands/Convert.swift
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio.git", | ||
"state" : { | ||
"revision" : "2d8e6ca36fe3e8ed74b0883f593757a45463c34d", |
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.
Are we expecting this update?
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.
No. I'll fix it when I merge main.
} | ||
|
||
let links: [(link: String, comment: String?)] = taskGroup.references.compactMap { (curatedReference: ResolvedTopicReference) -> (String, String?)? in | ||
guard !alreadyCurated.contains(curatedReference.absoluteString) else { return nil } |
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.
IIUC this only checks if the reference we are looking at was curated as a direct descendent of the node we are currently processing?
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 catch. Yes, that is what this is checking. However, I had already tested that this works with any curation so I went to look at why that worked... It turns out that AutomaticCuration.topics(for:withTraits:context:)
already checks if the link is curated anywhere, so this check isn't 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.
Fantastic! I think that will simplify the code somewhat.
|
||
text.append("\n\n### \(taskGroup.title ?? "<!-- This auto-generated topic has no title -->")\n") | ||
|
||
let longestLink = links.map(\.link.count).max()! /* `links` are non-empty */ + 7 /* the extra characters used to make the link "\n- ``" before and "``" after */ |
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.
This is a slightly confusing variable name, took a little while to understand this measures the longest line without a comment. I wonder if generating the String components first and then calculating padding might be more readable, even though it introduces an extra loop over the links, something along these lines:
let linkTextFragments = links.map { (link: "\n- ``\($0.link)``", comment: $0.comment.map { " <!-- \($0) -->" }) }
let longestLinkLine = linkTextFragments.map(\.link.count).max()!
let curationText = linkTextFragments
.map { $0.comment == nil ? $0.link : $0.link.padding(toLength: longestLinkLine, withPath: " ", startingAt: 0).append($0.comment!) }
.joined()
text.append(curationText)
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 incorporated the code that wraps the link and comment text in markup into the compactMap
above. That made the code that computes the longest link and appends the markup strings easier to follow.
# Conflicts: # Sources/SwiftDocCUtilities/Docc.swift
@swift-ci please test |
Bug/issue #, if applicable: rdar://98528457
Summary
This adds an experimental command to write the auto-generated curation to documentation extensions files.
In some workflows outside of build integrations this can be a way to generate a starting point for curation and to determine what symbol disambiguation is needed to curate symbols with name collisions.
The new command also has two options to control which symbols to emit documentation extensions files for:
--from-symbol <symbol-link>
and--depth <limit>
For example, passing
--depth 0
will only emit a documentation extension file for the module (emitting the auto-generated curation for top-level symbols).Passing
--from-symbols SomeClass
will emit documentation extension files for "SomeClass" and its sub hierarchy.Passing
--from-symbols SomeClass
and--depth 1
will emit documentation extension files for "SomeClass" and its direct descendants.Passing neither
--from-symbols
nor--depth
will emit documentation extension files for every symbol in the project.If you want the generated documentation extension files to be emitted in a separate location you can pass an explicit output path.
Dependencies
None
Testing
In a "process catalog" workflow
This functionality is mainly intended for workflows that aren't tied to a build integration and that can call a docc command other than "convert." Because of this, most of the configurability is only available in the new
process-catalog
commandEmit generated curation for symbol graphs;
A new "Generated.docc" catalog will be created in the current directory
Inspect the generated documentation extensions;
find Generated.docc
Manually recreate some of the generated curation.
Emit generated curation in addition to what's manually curated
Inspect the generated documentation extensions;
find YourRenamedCatalog.docc
Remove some manual curation and some generated documentation extension files again
Add an article to the documentation catalog
Emit generated curation into a different output location
Inspect the input documentation catalog;
find YourRenamedCatalog.docc
This catalog shouldn't be modified by the previous command
Inspect the output documentation catalog;
find NewCatalog.docc
Emit only a documentation file for the module
Inspect the documentation catalog;
find YourRenamedCatalog.docc
Emit documentation files for the specific symbol sub hierarchy
Inspect the documentation catalog;
find YourRenamedCatalog.docc
Try emitting documentation files for the symbol that doesn't exist
In a "convert" workflow
Add the
--experimental-modify-catalog-with-generated-curation
flag to adocc convert
call that uses a documentation catalog,After the conversion, the catalog may contain generated documentation extension files with auto-generated curation.
mkdir Empty.docc
find Empty.docc
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded