-
Notifications
You must be signed in to change notification settings - Fork 143
Format Swift symbol declarations using swift-format
#1048
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
It would also be neat if you could format the declaration at a series of page widths (e.g. one for desktop and one for mobile) so that users on narrower screens don’t have to scroll horizontally to read the declaration! |
That sounds like a cool idea, although it's less clear to me how long, complex declarations should be formatted specially for small width viewports. That could be a great future improvement if there's a clear configuration that works better for that scenario though. |
Bug/issue #, if applicable: 135820356
Summary
This PR adds a new
--enable-experimental-declaration-formatting
feature flag to thedocc convert
command. When this new experimental flag is enabled, Swift-DocC will utilize API from the swift-format package to format Swift symbol declarations.Example declaration:
Example declaration (using
--enable-experimental-declaration-formatting
):The benefits from doing this:
Some minor drawbacks:
Dependencies
Introduces 2 new Swift package dependencies used in the formatting process:
Testing
Steps:
--enable-experimental-declaration-formatting
flag when runningdocc convert
on a DocC catalog with Swift symbolsChecklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeededOpen questions
I'm marking this as a draft/work-in-progress PR, because I have a few questions about the implementation for this that I would like some feedback on:
Due to incompatibilities between the new Swift package dependencies, I had to bump the supported macOS platform of Swift-DocC to be able to build this branch. Is there a better way to resolve the supported platforms between packages to avoid this or do something better here?
See: https://github.com/mportiz08/swift-docc/blob/2be640012cc15aeefcda0176933b56ccec4dbc26/Package.swift#L22
Right now I'm just overwriting the normal
tokens
field in Render JSON when the feature flag is enabled. Are there any preferences on how I should approach the Render JSON?Options:
tokens
when experimental flag is usedtokens
and also add aformatted: true
property to the declaration JSONformattedTokens
field that lives alongsidetokens
After I get help with those questions, I think it would make sense to maybe do a quick post in the Swift forums and then remove the draft status from this PR :)