CodeEdit icon indicating copy to clipboard operation
CodeEdit copied to clipboard

Add experimental SwiftUI preview runner

Open AryanRogye opened this issue 6 months ago • 1 comments

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

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

Screenshots

Screenshot 2026-05-04 at 6 38 12 PM

AryanRogye avatar May 05 '26 00:05 AryanRogye

⚠️ 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 avatar May 05 '26 00:05 AryanRogye