Skip to content

Snippets should not be limited to Snippets directory #1500

Description

@ktoso

Feature Name

Snippets from any directory

Description

The docs say:

If you prefer, you can specify the relative path from the package’s root directory (by including a
“Snippets/” prefix). You can also include the package name—as defined in Package.swift—before the
“Snippets/” prefix. Neither of these leading path components are necessary because all your snippet code
files are always located in your package’s “Snippets” directory.

Earlier Versions
Before Swift-DocC 6.2.1, the @Snippet path needed to include both the package name component and the “Snippets” component: @Snippet(path: "my-package/Snippets/example-snippet")

Which basically means I have to copy or symlink my Samples/ projects into Snippets in order to use snippets, very confusing people contributing to the project.

We should be able to just

`@Snippet(path: "my-package/Samples/MySample/Sources/FirstExample/example-snippet")`

because this way those are not only compiled but also run tests against as I verify my samples.

Motivation

swift-java has extensive examples and every single feature has a sample.

We want to use those in documentation snippets, without symlinking or "working around" docc decisions that force copying the same samples into Snippets/

Importance

Reduce code duplication as well as improve testing of snippets.

Alternatives Considered

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements or enhancements to existing functionality

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions