-
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 new DisplayName directive to customize symbol names #92
Add new DisplayName directive to customize symbol names #92
Conversation
rdar://72969138
Also, remove language variance for module name related properties.
@@ -148,7 +148,8 @@ public struct DocumentationNode { | |||
/// > Warning: Using this initializer will not report any diagnostics raised during the initialization of `DocumentationNode`. | |||
@available(*, deprecated, message: "Use init(reference:symbol:platformName:moduleName:article:engine:) instead") | |||
public init(reference: ResolvedTopicReference, symbol: SymbolGraph.Symbol, platformName: String?, moduleName: String, article: Article?, problems: inout [Problem]) { |
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.
It would be good if to remove this initializer. It's been deprecated for a while now.
Package.resolved
Outdated
"branch": "main", | ||
"revision": "9a9050095ec93853c0ed01930a9d108d79dc4776", | ||
"branch": "unlabeled-directive-argument", | ||
"revision": "5cb5ae2c69fe2d0d490fe62fb119bd724fd98ac6", |
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.
What's your plan for landing these changes? It doesn't look like we're introducing new API in that branch that we're using in DocC, but I assume that some tests will fail without the Swift-Markdown changes?
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 plan on landing the Swift-Markdown changes first and then this. Without the Swift-Markdown changes, this new directive (and the tests that make use of it) will encounter parsing errors.
@@ -12,11 +12,12 @@ import Foundation | |||
import SymbolKit | |||
|
|||
/// A type that provides documentation bundles that it discovers by traversing the local file system. | |||
public struct GeneratedDataProvider: DocumentationWorkspaceDataProvider { | |||
public class GeneratedDataProvider: DocumentationWorkspaceDataProvider { |
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.
Can you elaborate here? Switching this to a class makes this type harder to use in concurrent environments. Also, might want to make this final
.
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.
Yes. This is driven by needing to know what data to return from contentsOfURL
. That data depend on if the generated bundle contains one or more modules. However, the argument to this method doesn't indicate one or the other so the number of modules (or its derivate values) need to be stored as private state. The information needed to know if the bundle represents one or more modules isn't known until bundles(options:)
is called so it can't be computed during initialization.
Given the choice between making one provider a class or making bundles(options:)
a mutating func I went with the former because it was a smaller change but I can see the argument for making mutation this a formal part of the provider API.
In practice, a provider is only asked to provide its bundles once and is only asked to provide content for urls in the returned bundle, so this won't have any impact on concurrency. If a developer did set up a shared GeneratedDataProvider with more than one documentation context, the real issue would be calling bundles(options:)
twice.
This class isn't open
, so making it final
would only make a difference within Swift-DocC. I don't think we have a case for subclassing this but we don't strictly have a case for not allowing subclassing within Swift-DocC either.
} | ||
let extendedModule: String? = unifiedSymbol.mixins | ||
.first(where: { $0.0.platform == platformName })?.value | ||
.getValueIfPresent(for: SymbolGraph.Symbol.Swift.Extension.self)?.extendedModule |
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.
Not sure I understand this change, can you elaborate? Should we not traverse the mixins
for each language variant the symbol is available in?
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.
From what I understand, module names are required to be the same in all languages. The Symbol
semantic no longer stores variants of module related information so this computes a single language agnostic value.
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 that makes sense, because the UnifiedSymbolGraph
logic relies on the symbol graph files for each language variant of a module to be the same, right @QuietMisdreavus?
let isDocumentationExtension = title.child(at: 0) is AnyLink | ||
if !isDocumentationExtension, let metadata = optionalMetadata, let displayName = metadata.displayName { | ||
let diagnosticSummary = """ | ||
A \(DisplayName.directiveName.singleQuoted) directive is only supported in documentation extensions files. To customize the display name of an article, change the content of the level-1 heading. |
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.
A \(DisplayName.directiveName.singleQuoted) directive is only supported in documentation extensions files. To customize the display name of an article, change the content of the level-1 heading. | |
A \(DisplayName.directiveName.singleQuoted) directive is only supported in documentation extension files. To customize the display name of an article, change the content of the level-1 heading. |
let solutions: [Solution] | ||
if let displayNameRange = displayName.originalMarkup.range, let titleRange = title.range { | ||
let removeDisplayNameReplacement = Replacement(range: displayNameRange, replacement: "") | ||
let changeTitleReplacement = Replacement(range: titleRange, replacement: "# \(displayName.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!
|
||
|
||
/// A cache of plain string module names, keyed by the module node reference. | ||
private var moduleNameCache: [ResolvedTopicReference: String] = [:] |
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.
Not sure I understand the need for this cache, rather than just using the node's title. Is this for performance?
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.
Yes, this is only for performance. The module symbol's name will be displayed on all symbol's pages so it's a good candidate for a value to cache.
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.
Ok, that makes sense. Wondering if we should make this an IOU so that we don't accidentally access it before it's been populated. We do the same for DocumentationContext.rootModules
.
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 that's a good idea. I made this non-optional and added asserts about how this API is used.
@swift-ci please test |
- Assert if module names are not found - Fix spelling in Article diagnostic message
3ff4c32
to
609e200
Compare
@swift-ci please test |
@swift-ci please test |
@swift-ci please test |
Bug/issue #, if applicable: SR-15572 rdar://72969138
Summary
This adds a new
@DisplayName
directive to allow for customization of symbol display names, as described in this forums post.There are two pieces that don't work like what's described in that forums post yet:
Dependencies
This depends on swiftlang/swift-markdown#27
Testing
With a documentation catalog
In a documentation catalog with symbol graph files and documentation extension files:
Preview the documentation for that docc catalog with
docc preview /path/to/Example.docc
In the documentation extension file for the module symbol: add a display name directive. For example:
Navigate to that page in the preview. The custom name ("Test name") should appear as the title, technology name, and breadcrumb for that symbol.
Navigate to a child symbol within that technology. The custom name ("Test name") should appear as the technology name and in the breadcrumbs for that symbol.
Without a documentation catalog
With a collection of symbol graph files:
Navigate to that page in the preview. The custom name ("Test name again") should appear as the title, technology name, and breadcrumb for that symbol.
Navigate to a child symbol within that technology. The custom name ("Test name again") should appear as the technology name and in the breadcrumbs for that symbol.
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded