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

Support resolving code file references in ConvertService #570

Merged

Conversation

d-ronnqvist
Copy link
Contributor

@d-ronnqvist d-ronnqvist commented Apr 27, 2023

Bug/issue #, if applicable: rdar://107965493

Summary

This enables convert service requests to resolve file assets that are references in the tutorial steps. This is done by asking the context to resolve the file asset if its data doesn't already exist.

Dependencies

None

Testing

In a client that uses ConvertService:

  • Verify that passing an tutorial file with steps using @Code references result in DocC returning a render node with file references for those code files with line highlights for the differences between the files' content.

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

@d-ronnqvist d-ronnqvist marked this pull request as ready for review May 2, 2023 18:41
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@@ -74,6 +76,21 @@ public struct RenderNodeTranslator: SemanticVisitor {
return assetReference
}

private func fileContents(with fileReference: ResourceReference) -> String? {
// Check if the file is a local asset that can be read directly from the context
if let fileData = try? context.resource(with: fileReference) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It looks like this logic is duplicated at least once – should we consider moving this to a specific method in the DocumentationContext?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Twice is below my threshold for duplication of something this small. I'm also thinking that this behavior would probably conceptually be more relevant to the asset manager or the data provider but moving it to either of those places would be bigger than this.

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist merged commit de843c4 into swiftlang:main May 5, 2023
@d-ronnqvist d-ronnqvist deleted the convert-service-file-references branch May 5, 2023 00:54
d-ronnqvist added a commit to d-ronnqvist/swift-docc that referenced this pull request May 5, 2023
* Support resolving code file references in ConvertService

rdar://107965493

* Support highlighting lines in resolved file assets
d-ronnqvist added a commit that referenced this pull request May 9, 2023
* Support resolving code file references in ConvertService

rdar://107965493

* Support highlighting lines in resolved file assets
d-ronnqvist added a commit to d-ronnqvist/swift-docc that referenced this pull request May 9, 2023
* Support resolving code file references in ConvertService

rdar://107965493

* Support highlighting lines in resolved file assets
d-ronnqvist added a commit that referenced this pull request May 10, 2023
* Support resolving code file references in ConvertService

rdar://107965493

* Support highlighting lines in resolved file assets
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