Skip to content

Support native preview arguments#167

Merged
BarredEwe merged 1 commit into
mainfrom
codex/native-preview-arguments
Jul 9, 2026
Merged

Support native preview arguments#167
BarredEwe merged 1 commit into
mainfrom
codex/native-preview-arguments

Conversation

@BarredEwe

Copy link
Copy Markdown
Owner

Summary

This PR adds support for native SwiftUI parameterized previews using the #Preview(..., arguments: ...) API. Prefire now parses the arguments: expression and the preview closure parameter pattern, then expands each argument into a distinct generated snapshot and Playbook preview.

The issue was that Prefire treated every #Preview macro as a single preview body. With native SwiftUI argument previews, that would only generate one snapshot/playbook entry even though SwiftUI presents the preview as a family of variants. The parser also previously depended on first-line string parsing for preview metadata, which becomes brittle when arguments: and multiline signatures are involved.

The fix extends RawPreviewModel with argument metadata parsed via SwiftSyntax, keeps compatibility with existing trait parsing, and updates both generated templates to iterate over preview arguments. Each generated variant gets a distinct name based on the base preview name, argument index, and argument description.

Changes

  • Parse native #Preview(..., arguments: values) { argument in ... } syntax.
  • Support tuple-style closure arguments such as { prefix, suffix in ... } by destructuring each argument value in generated code.
  • Expand parameterized previews in snapshot test generation.
  • Expand parameterized previews in Playbook model generation.
  • Add README documentation for the native SwiftUI arguments syntax.
  • Add parser and generator tests for snapshot and Playbook templates.

Validation

  • Ran swift test in PrefireExecutable after rebasing on origin/main.
  • Result: 51 tests passed, 0 failures.

@BarredEwe
BarredEwe force-pushed the codex/native-preview-arguments branch 2 times, most recently from 85e4123 to d569f34 Compare July 9, 2026 08:35
@BarredEwe
BarredEwe force-pushed the codex/native-preview-arguments branch from d569f34 to e551dc0 Compare July 9, 2026 08:42
@BarredEwe BarredEwe changed the title [codex] Support native preview arguments Support native preview arguments Jul 9, 2026
@BarredEwe
BarredEwe marked this pull request as ready for review July 9, 2026 08:48
@BarredEwe
BarredEwe merged commit 4da639e into main Jul 9, 2026
5 checks passed
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.

1 participant