This looks really great! I'm excited to start using these in docs.
I just had a few questions but I'm definitely a +1 here.
For the integration with Swift-DocC:
@Snippet(path: "my-package/Snippets/Snippet1")
The path argument consists of the following three components:
my-package : The package name, as taken from the Package.swift manifest.
Snippets : An informal namespace to differentiate snippets from symbols and articles.
Snippet1 : The snippet name taken from the snippet file basename without extension.
This path structure makes sense to me as an absolute link but I'm wondering if we should allow relative linking here? A DocC catalog is generally associated with only a single Swift Package so we should be able to infer the package name. And if I'm explicitly using an @Snippet directive, I'm not sure the Snippets namespace in the path should be required either. I like having the full absolute path as a measure of future-proofing (what if we want to allow linking to Snippets in a regular <doc:> link in the future for example), but it seems like we should support something like:
@Snippet("Snippet1")
in addition to
@Snippet(path: "package-name/Snippets/Snippet")
to better support the common scenario.
For the SwiftPM portion, I'm a little concerned about not exposing any controls for the "Snippets" directory.
SwiftPM will automatically find snippet files with the following pattern:
./Snippets/*.swift
./Snippets/*/*.swift
Should we be exposing API in the Package model that allows for customization of where this directory belongs? I like having the top-level Snippets directory as a default to match Tests and Sources. But with those other target types, I'm able to customize the directory using the path argument.
//! Line comments prefixed with ! will
I don't have a very strong opinion here but I wonder if this syntax will be confused with Objective-C and other C-based language's doc comment syntax. Someone coming from Objective-C might assume this is just another flavor of Swift's doc comment syntax (and interchangeable with /// and /**) when it's explicitly not.
Should we consider using something like //: instead?
Again, this is looking really great. Having the ability to actually regularly compile code examples that are shown in documentation is going to really impactful. (And I know this is just the beginning of what we can do with Snippets.) Thank you!