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

Add --include-extended-types flag #34

Merged
merged 5 commits into from Jan 31, 2023

Conversation

theMomax
Copy link
Contributor

@theMomax theMomax commented Nov 13, 2022

Bug/issue #, if applicable: apple/swift-docc#210

Summary

The --include-extended-types flag is transformed to the --emit-extension-block-symbols flag of the swift package dump-symbol-graph command. It is available starting from Swift 5.8.

Dependencies

All dependencies have been merged. For an overview see apple/swift-docc#210 (comment).

Testing

  1. Use a toolchain generated from main or release/5.8 branches after December 21st
  2. Use the base branch of this PR when adding the swift-docc-plugin to your Package.swift:
dependencies: [
    .package(url: "https://github.com/themomax/swift-docc-plugin", branch: "add-extended-types-flag")
]
  1. Add the --include-extended-types flag when running your command

Verifying the basic functionality can be done with this sample repository. Running swift package --disable-sandbox preview-documentation --include-extended-types --target NestedTypes should produce the result shown below:

image

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:
    Swift 5.7.2: .bin/test succeeded
    Swift 5.8/main nightly: .bin/test succeeded after removing the --parallel flag from swift test invocations in the script (Running swift test --parallel on any package fails for me with an error similar to the one described here. However, this is an issue with the nightly toolchains I've been getting for a while now.)
  • Updated documentation if necessary

@theMomax theMomax changed the title Add --include-extended-types flag Add --include-extended-types flag Nov 13, 2022
@theMomax theMomax changed the title Add --include-extended-types flag Add --include-extended-types flag Nov 13, 2022
@theMomax theMomax marked this pull request as ready for review December 22, 2022 10:36
@theMomax
Copy link
Contributor Author

theMomax commented Jan 2, 2023

@ethan-kusters this PR is ready for review now!

Copy link
Collaborator

@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 added a few initial thoughts.

print("warning: detected '--emit-extension-block-symbols' option, which is incompatible with your swift version (required: 5.8)")
#endif
default:
print("warning: detected unknown dump-symbol-graph option '\(argument)'")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we fatalError here? This is a programmer error, right? It shouldn't be possible to receive an unknown flag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the incompatible version I'd prefer to do it the same way as in SwiftPM, i.e. emitting a warning (see apple/swift-package-manager#5892 (comment)).

The typed configuration options you suggested make the default case for unknown flags redundant anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the fatalError here, as it becomes relevant again with the approach from #28

@@ -19,10 +19,25 @@ public struct ParsedArguments {
return arguments.contains("--help") || arguments.contains("-h")
}

/// Returns the arguments that could be passed to `swift package dump-symbol-graph`.
///
/// In practice, however we won't invoke the `dump-symbol-graph` command via the command line,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we consider a different way to represent this information instead of strings representing the flags since we're going to re-parse them anyway?

I think tying this implementation to swift package dump-symbol-graph is kind of unnecessarily confusing for folks who might be familiar with SwiftPM plugins but not that specific command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that might be a good idea. I gave it a try based on the following protocol:

/// Transforms a set of arguments, transferring information to a typed configuration.
protocol ArgumentsTransformer: ArgumentsTransforming {
    associatedtype Configuration
    /// Apply the transformation to the given arguments and configuration.
    func transform(arguments: inout Arguments, configuration: inout Configuration)
}

Please take a look and let me know what you think about it. I'm not super happy with the result, but I'm also not really happy with the whole CLI parsing setup in this plugin. I'm also wondering if a ArgumentParser based rewrite wouldn't be favorable in general.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also wondering if a ArgumentParser based rewrite wouldn't be favorable in general.

This is 100% what I'd like to do long-term. We're just blocked on SwiftPM support to allow command plugins to have dependencies: apple/swift-package-manager#5574.


I'm worried this approach with the generic Configuration is over-optimizing for what we need here. I'm curious if you've looked at the approach in #28? It's less extensible but since we're likely going to need to overhaul our argument parsing solution here in the long-term anyway I wonder if something along those lines would be more maintainable in the shorter term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is 100% what I'd like to do long-term. We're just blocked on SwiftPM support to allow command plugins to have dependencies: apple/swift-package-manager#5574.

Ah, yeah, I forgot about that :)


I'm worried this approach with the generic Configuration is over-optimizing for what we need here. I'm curious if you've looked at the approach in #28? It's less extensible but since we're likely going to need to overhaul our argument parsing solution here in the long-term anyway I wonder if something along those lines would be more maintainable in the shorter term.

I felt so too, and, now that I've looked at #28, I agree it's the better short-term solution. I adopted the approach, making sure to cause as little merge-conflicts as possible. I only kept the filter(for:) function in ParsedArguments from my approach, as I felt like without it it would be too easy to accidentally have flags passed to docc that are not meant for it.

Sources/SwiftDocCPluginUtilities/ParsedArguments.swift Outdated Show resolved Hide resolved
@ethan-kusters
Copy link
Collaborator

@swift-ci please test

1 similar comment
@ethan-kusters
Copy link
Collaborator

@swift-ci please test

@@ -19,10 +19,25 @@ public struct ParsedArguments {
return arguments.contains("--help") || arguments.contains("-h")
}

/// Returns the arguments that could be passed to `swift package dump-symbol-graph`.
///
/// In practice, however we won't invoke the `dump-symbol-graph` command via the command line,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also wondering if a ArgumentParser based rewrite wouldn't be favorable in general.

This is 100% what I'd like to do long-term. We're just blocked on SwiftPM support to allow command plugins to have dependencies: apple/swift-package-manager#5574.


I'm worried this approach with the generic Configuration is over-optimizing for what we need here. I'm curious if you've looked at the approach in #28? It's less extensible but since we're likely going to need to overhaul our argument parsing solution here in the long-term anyway I wonder if something along those lines would be more maintainable in the shorter term.

Sources/SwiftDocCPluginUtilities/ParsedArguments.swift Outdated Show resolved Hide resolved
Copy link
Collaborator

@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! Thank you so much for your work here – really excited to get this in.

Could you add a of couple integration tests as well before landing this? I put together a patch just as an example (the integration test suite is a little tricky/weird) that I think gives enough basic coverage but feel free to expand from there or discard it entirely:

add-integration-test.patch

git apply add-integration-test.patch

You can open up the sub-package in the swift-docc-plugin/IntegrationTests subdirectory to run the tests. (I think the parent package needs to be closed for things to work.)

@theMomax
Copy link
Contributor Author

@ethan-kusters I expanded your test with a protocol conformance, but I don't think it makes sense to go any further. After all, the tests here should just verify that the plugin invokes the toolchain correctly, which can easily be verified with these simple cases. Anything beyond that should be/is tested in swift-docc and libSymbolGraphGen in the compiler.

@ethan-kusters
Copy link
Collaborator

@swift-ci please test

1 similar comment
@ethan-kusters
Copy link
Collaborator

@swift-ci please test

Copy link
Collaborator

@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! Thank you! 🚀

The --include-extended-types flag is transformed to the --emit-extension-block-symbols flag of the
swift package dump-symbol-graph command. It is available starting from Swift 5.8.
@ethan-kusters
Copy link
Collaborator

@swift-ci please test

@daniel-grumberg
Copy link

@swift-ci please test

sofiaromorales added a commit to sofiaromorales/swift-docc-plugin that referenced this pull request Feb 13, 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.

None yet

3 participants