Skip to content

Add experimental SwiftUI preview runner - #2176

Draft
AryanRogye wants to merge 1 commit into
CodeEditApp:mainfrom
AryanRogye:feature/swiftui_preview
Draft

AryanRogye wants to merge 1 commit into
CodeEditApp:mainfrom
AryanRogye:feature/swiftui_preview

Conversation

@AryanRogye

Copy link
Copy Markdown

Description

This PR adds an experimental proof-of-concept SwiftUI preview runner for CodeEdit.

The goal is to explore rendering SwiftUI #Preview content directly inside the editor. When a Swift file contains a #Preview, CodeEdit can show a preview canvas next to the source editor, generate a temporary preview package, build it, dynamically load the compiled output, and render the resulting SwiftUI view inside the app.

Changes include:

  • Adds SwiftSyntax-based #Preview detection and extraction
  • Adds a preview pipeline: source processing → temporary package generation → build → dynamic load → render
  • Adds a SwiftUI preview canvas inside the editor
  • Adds AppKit hosting support for rendering the compiled preview view
  • Links SwiftSyntax and SwiftParser for source processing
  • Temporarily disables App Sandbox so the preview runner can build and dynamically load generated preview code

This is intentionally a proof of concept, not the final preview architecture.

Important limitations:

  • Currently works best for self-contained SwiftUI files.
  • Previews that depend on broader project/module context may not compile yet.
  • Dynamic preview execution requires sandboxing to be disabled.
  • The final security model should likely run previews in a separate helper process instead of loading arbitrary preview code into the main CodeEdit process.

Related Issues

#140

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Screenshot 2026-05-04 at 6 38 12 PM
- Adds SwiftUI preview pipeline (compile → load → render)
- Integrates preview UI into editor
- Adds SwiftSyntax/SwiftParser for source processing
- Updates project configuration for preview support

Note: This is a proof of concept and currently requires sandboxing to be disabled for dynamic preview execution.
@AryanRogye

AryanRogye commented May 5, 2026 •

Copy link
Copy Markdown
Author

⚠️ This is not meant to be merged as-is. I opened this PR to get early maintainer feedback on whether this direction is worth continuing.

@AryanRogye
AryanRogye marked this pull request as draft May 5, 2026 00:09
@0xWDG
0xWDG requested review from a team, bombardier200 and thecoolwinter June 15, 2026 09:52

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant