Skip to content

Add experimental SwiftUI preview runner#2176

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

Add experimental SwiftUI preview runner#2176
AryanRogye wants to merge 1 commit intoCodeEditApp: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
Copy link
Copy Markdown
Author

AryanRogye commented May 5, 2026

⚠️ 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
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