Hi everyone, I'm happy to propose a new functionality to link symbol documentation pages back to their source code. This is a feature a lot of you had requested, here's the link to the original post by @johannesweiss. The goal of this feature is to make it easier for developers to quickly locate the lines where a symbol is declared in.
The source file link will be placed under the declaration code snippet.
This is an opt-in feature that you use via the following two new flags:
swift package generate-documentation \
--source-service github \ // GitHub, GitLab, or BitBucket
--source-service-base-url https://github.com/<org>/<repo>/blob/main
Documentation pages for symbols automatically gain a link to the declaration in source:
I think there's a lot of value in hardcoding URL formats for popular hosting services like GitHub, so that users can use this functionality without needing to know how GitHub formats its URLs. The placeholder approach you propose is more flexible though as a future enhancement, e.g., to support source services other than the ones this feature supports natively.
Yes, we're unblocked on this. Our main limiting factor right now is team bandwidth, as we'd like to extract the documentation from the swift-nio repo to avoid it continuing to bloat the repo clone time as the current docs do.
Hi @franklin can you share some example project where I could try it ?
I tried to follow the steps in the documentation, but it did not work.
My setup:
I installed locally the latest docc and docc-renderer
I added DOCC_EXEC to project file
I added the additional flags (Other DocC Flags): --source-service github --source-service-base-url https://github.com/gadireddi226/OSLogStoreExample/blob/main --checkout-path /path/to/OSLogStoreExample
I tried it with the latest docc version and latest docc-renderer and I added the additional flags.
But it still does not seem to generate the link to sources.
Hi @gadireddi226, following the steps you outlined on your project, I'm able to see the links to GitHub in the rendered documentation. Are you browsing your documentation in your web browser, or in Xcode? Note that the renderer that's built into Xcode's documentation viewer will support source links in an upcoming release of Xcode.
To view source links right now, you can use the main branch of Swift-DocC Render and publish your documentation to GitHub Pages or preview locally by running a command like python3 -m http.server within your DocC archive and opening http://localhost:8000/documentation/testoslogger in your browser.
If you run into further issues, I'd encourage you to create a GitHub Issue so investigate this further. I'd prefer keeping this forum thread focused on the feature's evolution. Thank you!