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

Provide ConvertService with mapping of USRs to minimal access level required for extended documentation to be available #555

Conversation

daniel-grumberg
Copy link
Contributor

Provide ConvertService with mapping of USRs to minimal access level required for extended documentation to be available

rdar://105460209

Bug/issue #, if applicable:

Summary

Provide a way for the convert service to add information in the render node to say if there is available additional documentation for a given symbol. This information is provided by the client on a per symbol access control level basis.

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
  • Updated documentation if necessary

@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@ethan-kusters ethan-kusters left a comment

Choose a reason for hiding this comment

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

Looks great! Just left a couple of questions/comments.

/// DocC sets the ``RenderMetadata/hasExpandedDocumentationForSymbols`` property to `true`
/// for these symbols if their access level meets the minimum requirement, so that renderers can display a
/// "View More" link that navigates the user to the full version of the documentation page.
public var symbolIdentifiersWithExpandedDocumentation: [String: AccessControlLevel]?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider passing a more generically named struct here that itself contains AccessControlLevel? I think it's likely we'll want to pass additional requirements in the future.

Suggested change
public var symbolIdentifiersWithExpandedDocumentation: [String: AccessControlLevel]?
public var symbolIdentifiersWithExpandedDocumentation: [String: ExpandedDocumentationRequirement]?
struct ExpandedDocumentationRequirement: Codable {
    let accessLevel: AccessControlLevel?
}

@@ -250,13 +257,22 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
// Copy images, sample files, and other static assets.
try outputConsumer.consume(assetsInBundle: bundle)

let symbolIdentifiersMeetingRequirementsForExpandedDocumentation: [String]? = symbolIdentifiersWithExpandedDocumentation?.compactMap { (identifier, accessControlLevelRequirement) -> String? in
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need to consider whether the symbol is underscored and if it's SPI here as well.

We could leave it a TODO to pass in those requirements later-on and hard-code for them now but it might be nice to just pass them in.

Eventually I'll imagine us needing to support the recently added @_documentation(visibility: ...) modifier as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That''s a good idea, I will do that and the suggestion of making it easier to add different kinds of requirements here.

}

return lhs < rhs
return AccessControlLevel(from: lhs) < AccessControlLevel(from: rhs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh interesting! I was a little concerned about introducing the idea of comparable access levels to Swift-DocC in this PR but since it's already here and used I like how you've made it more generic and accessible. We should look at adding package here if/when it's approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I decided to add the type so that we wouldn't have to traffic strings or reexport SymbolKit. It would be good to have a set of vocabulary types internal to DocC

@daniel-grumberg daniel-grumberg force-pushed the convert-service-has-expanded-docs branch 3 times, most recently from 06cb3d9 to d9e5a61 Compare April 26, 2023 19:36
@@ -288,4 +301,14 @@ extension ConvertRequest {
self.character = character
}
}

public struct ExpandedDocumentationRequirements: Codable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Would be good to document these.

@@ -11,18 +11,13 @@
import SymbolKit

extension SymbolGraph.Symbol.AccessControl: Comparable {
private var level: Int? {
private var level: UInt? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this change be in this PR? Swift generally advises against using UInt as a way to enforce positive values: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/thebasics/#UInt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it shouldn't be in here.


public struct ExpandedDocumentationRequirements: Codable {
public let accessControlLevels: [String]
public let canBeUnderscored: Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to support checking SPI here as well but we can leave that to a future PR.

@daniel-grumberg daniel-grumberg force-pushed the convert-service-has-expanded-docs branch from d9e5a61 to 85341fa Compare April 27, 2023 07:17
@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test

…equired for extended documentation to be available

rdar://105460209
@daniel-grumberg daniel-grumberg force-pushed the convert-service-has-expanded-docs branch from 85341fa to 9b3bd0c Compare April 28, 2023 08:35
@daniel-grumberg
Copy link
Contributor Author

@swift-ci please test

@daniel-grumberg daniel-grumberg merged commit 7ebe20f into swiftlang:main Apr 28, 2023
@daniel-grumberg daniel-grumberg changed the title Provide ConvertService with mapping of USRs to minimal access level required for extended documentation to be available [5.9] 🍒Provide ConvertService with mapping of USRs to minimal access level required for extended documentation to be available Apr 28, 2023
@daniel-grumberg daniel-grumberg changed the title [5.9] 🍒Provide ConvertService with mapping of USRs to minimal access level required for extended documentation to be available Provide ConvertService with mapping of USRs to minimal access level required for extended documentation to be available Apr 28, 2023
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.

2 participants