Files
zed/crates/gpui_platform/src/gpui_platform.rs
T
4deb9b1b69 GPUI updates (#51415)
- **Fix race condition in test_collaborating_with_completion**
- **WIP: Integrate scheduler crate into GPUI TestDispatcher**
- **WIP: scheduler integration debugging**
- **Fix formatting**
- **Unify RunnableMeta and add execution tracking to TestScheduler**
- **Remove unused execution tracking from TestScheduler and
TestDispatcher**
- **Add is_ready() to GPUI Task for API parity with scheduler**
- **Eliminate RunnableVariant::Compat - all runnables now have source
location metadata**
- **Update integration plans to reflect completed phases**
- **Simplify RunnableVariant to type alias**
- **Delegate TestDispatcher task queues to TestScheduler (Phase 2b)**
- **Remove waiting_hint/waiting_backtrace and debug logging from
TestDispatcher**
- **Remove wrapper methods from TestDispatcher - access scheduler()
directly**
- **Update integration plan with complete state and instructions for
full scheduler migration**
- **Use scheduler's native timer() and simplify TestDispatcher**
- **Fix rng() usage to lock mutex, update plan with SharedRng wrapper**
- **Add SharedRng wrapper for ergonomic random number generation**
- **Update plan: mark Phase 1 (SharedRng) as complete**
- **Update scheduler integration plan with Phase 2 investigation notes**
- **Phase 3: Delegate simulate_random_delay to
scheduler.yield_random()**
- **Phase 4: Remove TaskLabel**
- **Phase 5 (WIP): Simplify block_internal and remove unparkers**
- **Phase 5 Complete: Scheduler integration finished**
- **Update integration plan with code review findings**
- **Phase 6 & 7: Restore realtime priority support and delete dead
code**
- **Add TestApp and TestAppWindow for cleaner GPUI testing**
- **Fix formatting across the branch**
- **Fix Linux build: add explicit type annotation and rename
probability() to weight()**
- **Add TestApp and TestAppWindow for cleaner GPUI testing**
- **Rename TestAppWindow to TestWindow, internal TestWindow to
TestPlatformWindow**
- **Remove unused RunnableVariant imports on Linux**
- **Add STATUS.md for next agent**
- **Run cargo fmt**
- **Use per-app element arena only and scope test draws**
- **Fix collab tests for scheduler timing and ordering**
- **Store element arena on App and route element allocations through
draw scope**
- **Fix TestScheduler lock ordering between rng and state**
- **Fix inlay hints test by explicitly triggering refresh after viewport
setup**
- **Add scheduler integration regression risk analysis doc**
- **Fix tests: avoid caching Entity in global OnceLock for Codestral API
key**
- **Document learned weak point: global cached Entity handles break
across App contexts**
- **Add scheduler regression test for block_with_timeout continuation
and explicit time advancement**
- **Document TestScheduler timeout tick budget behavior and explicit
time advancement guidance**
- **Add test asserting realtime priority spawns panic under
TestDispatcher**
- **Document realtime priority determinism contract in tests**
- **Remove realtime priority until we have a concrete use case (cc
@localcc)**
- **Update STATUS for scheduler integration decisions and realtime
priority removal**
- **Fix prettier docs and clippy in scheduler tests**
- **Remove unused imports from Windows dispatcher**
- **WIP: scheduler integration debugging + agent terminal diagnostics**
- **Update scheduler integration status**
- **Remove temporary planning docs, consolidate into scheduler
integration doc**
- **Remove unrelated changes from scheduler integration**
- **Fix clippy errors**
- **Add STATUS.md with debugging instructions for Linux/Windows hang**
- **WIP: local changes needed by ex**
- **Add pointer capture API for stable drag handling**
- **Add pointer capture API for stable drag handling**
- **chore: update generated cargo manifests**
- **gpui: Expose ShapedLine::width() for pen advancement**
- **Remove git2 usage from util test.rs**
- **Store DiagnosticQuad bounds in logical Pixels**
- **WIP: executor and test_app changes for scheduler integration**
- **Expose font APIs publicly**
- **gpui: add typed diagnostics and record_diagnostic API**
- **WIP: gpui test window diagnostics changes**
- **Add LineCacheKey trait and shape_line_cached API for
content-addressable shaping**
- **Fix RenderGlyphParams field additions for Ex compatibility**
- **Add doc comment for recommended_rendering_mode, fix formatting**
- **Add scheduler_executor() method for Ex compatibility**
- **Fix TestWindow -> TestPlatformWindow in test_context.rs**
- **Add headless metal renderer and window focus improvements**
- **Fix double borrow in TestWindow::simulate_resize**
- **Fix cbindgen panic: remove default type parameter from
Diagnostic<T>**
- **Implement AppContext for HeadlessMetalAppContext**
- **Missing trait impls**
- **Add ShapedLine::split_at and eliminate re-shaping in soft wraps**
- **Add handoff doc for platform-neutral-tests merge**
- **Remove ex-only test infrastructure before merging main**
- **Add cross-platform HeadlessAppContext with pluggable text system**
- **Export platform_text_system() from gpui_windows for cross-platform
tests**
- **Restore TestApp/TestAppWindow with pluggable text system support**
- **Add TestApp::open_window_sized for tests that need specific window
dimensions**
- **Fix some warnings**
- **Fixes**
- **Add a platform-neutral headless renderer interface**
- **Synchronize Managed texture before CPU readback on discrete GPUs**
- **Allow creating TestDispatcher with custom scheduler**

Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: John Tur <john-tur@outlook.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
Co-authored-by: Antonio Scandurra <me@as-cii.com>
2026-03-12 22:15:12 +00:00

187 lines
5.6 KiB
Rust

//! Convenience crate that re-exports GPUI's platform traits and the
//! `current_platform` constructor so consumers don't need `#[cfg]` gating.
pub use gpui::Platform;
use std::rc::Rc;
/// Returns a background executor for the current platform.
pub fn background_executor() -> gpui::BackgroundExecutor {
current_platform(true).background_executor()
}
pub fn application() -> gpui::Application {
gpui::Application::with_platform(current_platform(false))
}
pub fn headless() -> gpui::Application {
gpui::Application::with_platform(current_platform(true))
}
/// Unlike `application`, this function returns a single-threaded web application.
#[cfg(target_family = "wasm")]
pub fn single_threaded_web() -> gpui::Application {
gpui::Application::with_platform(Rc::new(gpui_web::WebPlatform::new(false)))
}
/// Initializes panic hooks and logging for the web platform.
/// Call this before running the application in a wasm_bindgen entrypoint.
#[cfg(target_family = "wasm")]
pub fn web_init() {
console_error_panic_hook::set_once();
gpui_web::init_logging();
}
/// Returns the default [`Platform`] for the current OS.
pub fn current_platform(headless: bool) -> Rc<dyn Platform> {
#[cfg(target_os = "macos")]
{
Rc::new(gpui_macos::MacPlatform::new(headless))
}
#[cfg(target_os = "windows")]
{
Rc::new(
gpui_windows::WindowsPlatform::new(headless)
.expect("failed to initialize Windows platform"),
)
}
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
{
gpui_linux::current_platform(headless)
}
#[cfg(target_family = "wasm")]
{
let _ = headless;
Rc::new(gpui_web::WebPlatform::new(true))
}
}
/// Returns a new [`HeadlessRenderer`] for the current platform, if available.
#[cfg(feature = "test-support")]
pub fn current_headless_renderer() -> Option<Box<dyn gpui::PlatformHeadlessRenderer>> {
#[cfg(target_os = "macos")]
{
Some(Box::new(
gpui_macos::metal_renderer::MetalHeadlessRenderer::new(),
))
}
#[cfg(not(target_os = "macos"))]
{
None
}
}
#[cfg(all(test, target_os = "macos"))]
mod tests {
use super::*;
use gpui::{AppContext, Empty, VisualTestAppContext};
use std::cell::RefCell;
use std::time::Duration;
// Note: All VisualTestAppContext tests are ignored by default because they require
// the macOS main thread. Standard Rust tests run on worker threads, which causes
// SIGABRT when interacting with macOS AppKit/Cocoa APIs.
//
// To run these tests, use:
// cargo test -p gpui visual_test_context -- --ignored --test-threads=1
#[test]
#[ignore] // Requires macOS main thread
fn test_foreground_tasks_run_with_run_until_parked() {
let mut cx = VisualTestAppContext::new(current_platform(false));
let task_ran = Rc::new(RefCell::new(false));
// Spawn a foreground task via the App's spawn method
// This should use our TestDispatcher, not the MacDispatcher
{
let task_ran = task_ran.clone();
cx.update(|cx| {
cx.spawn(async move |_| {
*task_ran.borrow_mut() = true;
})
.detach();
});
}
// The task should not have run yet
assert!(!*task_ran.borrow());
// Run until parked should execute the foreground task
cx.run_until_parked();
// Now the task should have run
assert!(*task_ran.borrow());
}
#[test]
#[ignore] // Requires macOS main thread
fn test_advance_clock_triggers_delayed_tasks() {
let mut cx = VisualTestAppContext::new(current_platform(false));
let task_ran = Rc::new(RefCell::new(false));
// Spawn a task that waits for a timer
{
let task_ran = task_ran.clone();
let executor = cx.background_executor.clone();
cx.update(|cx| {
cx.spawn(async move |_| {
executor.timer(Duration::from_millis(500)).await;
*task_ran.borrow_mut() = true;
})
.detach();
});
}
// Run until parked - the task should be waiting on the timer
cx.run_until_parked();
assert!(!*task_ran.borrow());
// Advance clock past the timer duration
cx.advance_clock(Duration::from_millis(600));
// Now the task should have completed
assert!(*task_ran.borrow());
}
#[test]
#[ignore] // Requires macOS main thread - window creation fails on test threads
fn test_window_spawn_uses_test_dispatcher() {
let mut cx = VisualTestAppContext::new(current_platform(false));
let task_ran = Rc::new(RefCell::new(false));
let window = cx
.open_offscreen_window_default(|_, cx| cx.new(|_| Empty))
.expect("Failed to open window");
// Spawn a task via window.spawn - this is the critical test case
// for tooltip behavior, as tooltips use window.spawn for delayed show
{
let task_ran = task_ran.clone();
cx.update_window(window.into(), |_, window, cx| {
window
.spawn(cx, async move |_| {
*task_ran.borrow_mut() = true;
})
.detach();
})
.ok();
}
// The task should not have run yet
assert!(!*task_ran.borrow());
// Run until parked should execute the foreground task spawned via window
cx.run_until_parked();
// Now the task should have run
assert!(*task_ran.borrow());
}
}