Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 261487628f test(plugins): don't time the plugin host tests against the runner's speed
Three tests in crates/ide-host/tests/plugins.rs failed on slow CI runners
(main's last runs, #1226):

- The crash backoff test compared wall-clock waits between crashes, which
  polling and scheduling stretch (277 ms then 338 ms for 150 / 300 ms). It
  now checks that each crash is backed off and the third stops the plugin;
  the doubling is a unit test of `Limits::backoff`.
- The edit-path deadline test expected a call right after a slow one, and
  the first call to a restarted instance, to fit the 50 ms soft deadline.
  Those wait until the runner caught up.
- The concurrency test used a 300 ms budget for 200 ms calls; it now gives
  the calls a budget no runner misses and checks only that two 500 ms calls
  overlap (under 950 ms together).
2026-11-04 18:26:50 +08:00
l0ng-ai 48e23c012f test(plugins): time only the restart wait in the crash backoff test
The waits included the restart that ended them, and instantiating the plugin can take a few hundred milliseconds on CI, so a slow second restart made the third wait look no longer. Measure until the call that is let through and require the third wait to exceed the second by half the base backoff.
2026-11-04 17:26:25 +08:00
l0ng-ai 0bc0396f80 test(sdk): only use a subst drive that shows the test's own directory
The two mapped-drive tests run in parallel processes and could race for the same free drive letter, then see the other test's directory. Mark the target and accept a drive only when the marker shows through it.
2026-11-04 16:57:30 +08:00
l0ng-ai d20be9c5cc fix(window): declare the detach fullscreen flag only on macOS
It is read only in macOS code, so Linux and Windows builds failed on an unused variable.
2026-11-04 16:57:28 +08:00
l0ng-ai 2d3b7ebf54 fix(window): keep a fullscreen project window group in one Space on macOS (#1218)
Native fullscreen gives every window its own Space, so switching projects in a fullscreen window group left one Space and entered another: the desktop showed in between, and quick switching could drop out of fullscreen.

A grouped window now uses simple fullscreen for every member at once; switching projects only shows one window and hides the others. The green button, the system Enter Full Screen item and Toggle Full Screen take this path for grouped windows, which keep their window buttons; ungrouped windows keep native fullscreen. Menu bar and Dock auto-hide while any window is in simple fullscreen, and detaching or closing a tab keeps the rest of the group fullscreen.
2026-11-04 16:35:43 +08:00
8 змінених файлів з 270 додано та 21 видалено

No files matched your search

+30 -14
Переглянути файл
@@ -123,6 +123,19 @@ fn misbehave_pkg() -> PathBuf {
repo().join("crates/ide-plugin/tests/fixtures/misbehave")
}
/// Whether `f` holds within 5 s. A call a slow runner keeps waiting behind
/// another (or behind a new instance starting) holds once it caught up.
fn eventually(mut f: impl FnMut() -> bool) -> bool {
let until = Instant::now() + Duration::from_secs(5);
while !f() {
if Instant::now() > until {
return false;
}
std::thread::sleep(Duration::from_millis(20));
}
true
}
/// A theme package with a light and a dark theme, plus licence files, in `dir`.
fn write_theme_pair(dir: &Path) {
std::fs::create_dir_all(dir.join("t")).unwrap();
@@ -397,11 +410,11 @@ fn crashes_restart_with_backoff_until_the_circuit_opens() {
let info = f.host.info_of("misbehave").unwrap();
assert_eq!((info.status, info.stats.activations, info.error), (PluginStatus::Active, 2, None));
// Three in a row: stopped for the session, with growing waits between.
// Three in a row: stopped for the session, backing off between them (the wait
// doubles: `Limits::backoff`, tested where it is defined; wall-clock waits on CI
// are too noisy to compare).
f.take_events();
let mut waits = Vec::new();
for _ in 0..3 {
let started = Instant::now();
for crash in 0..3 {
let err = loop {
match f.run("misbehave", "panic", None) {
Err(e) if e.contains("restarts in") => std::thread::sleep(Duration::from_millis(20)),
@@ -409,9 +422,10 @@ fn crashes_restart_with_backoff_until_the_circuit_opens() {
}
};
assert!(err.contains("crashed"), "{err}");
waits.push(started.elapsed());
if crash < 2 {
assert!(f.run("misbehave", "echo", None).unwrap_err().contains("restarts in"), "backing off");
}
}
assert!(waits[2] >= backoff * 2 && waits[2] > waits[1], "{waits:?}");
let info = f.host.info_of("misbehave").unwrap();
assert_eq!(info.status, PluginStatus::Failed);
assert!(info.error.as_deref().is_some_and(|e| e.contains("3 times in a row")), "{:?}", info.error);
@@ -532,10 +546,10 @@ fn edit_path_calls_have_soft_and_hard_deadlines() {
// Slower than the soft deadline: dropped (however late this thread gets
// to look), but the instance lives on.
assert!(provider.highlights(&mis, "sleep:150").is_none());
std::thread::sleep(Duration::from_millis(150));
assert!(provider.highlights(&mis, "fast").is_some());
assert!(eventually(|| provider.highlights(&mis, "fast").is_some()));
let info = host.info_of("misbehave").unwrap();
assert_eq!((info.stats.slow_calls, info.stats.crashes, info.stats.activations), (1, 0, 1));
assert!(info.stats.slow_calls >= 1, "{:?}", info.stats);
assert_eq!((info.stats.crashes, info.stats.activations), (0, 1));
// Past the hard deadline: interrupted; the next call gets a new instance.
assert!(provider.highlights(&mis, "spin").is_none());
@@ -544,7 +558,8 @@ fn edit_path_calls_have_soft_and_hard_deadlines() {
let info = host.info_of("misbehave").unwrap();
assert_eq!(info.stats.crashes, 1, "{:?}", info.error);
assert!(info.error.as_deref().is_some_and(|e| e.contains("timed out after 400ms")), "{:?}", info.error);
assert!(provider.highlights(&mis, "fast").is_some());
// The new instance may take longer to start than the soft deadline on a slow runner.
assert!(eventually(|| provider.highlights(&mis, "fast").is_some()));
assert_eq!(host.info_of("misbehave").unwrap().stats.activations, 2);
}
@@ -553,9 +568,10 @@ fn edit_path_calls_have_soft_and_hard_deadlines() {
#[test]
fn providers_of_several_plugins_run_concurrently() {
let tmp = tempfile::tempdir().unwrap();
// A budget no runner misses, so only the overlap is measured.
let limits = Limits {
edit_soft: Duration::from_millis(300),
edit_hard: Duration::from_secs(2),
edit_soft: Duration::from_secs(5),
edit_hard: Duration::from_secs(10),
fuel: u64::MAX,
..Limits::default()
};
@@ -588,12 +604,12 @@ fn providers_of_several_plugins_run_concurrently() {
assert_eq!(host.provide_completion(&doc("fast"), at, None).len(), 2);
let started = Instant::now();
let items = host.provide_completion(&doc("sleep:200"), at, None);
let items = host.provide_completion(&doc("sleep:500"), at, None);
let elapsed = started.elapsed();
let mut from: Vec<&str> = items.iter().map(|(p, _)| p.as_str()).collect();
from.sort();
assert_eq!(from, ["slow-a", "slow-b"], "both within the budget");
assert!(elapsed < Duration::from_millis(350), "one after the other would take 400ms: {elapsed:?}");
assert!(elapsed < Duration::from_millis(950), "one after the other would take 1000ms: {elapsed:?}");
assert_eq!(host.info_of("slow-b").unwrap().stats.slow_calls, 0);
}
+10
Переглянути файл
@@ -303,6 +303,16 @@ pub fn net_host(url: &str) -> Result<String, String> {
#[cfg(test)]
mod tests {
#[test]
fn the_restart_backoff_doubles_up_to_a_minute() {
let limits = Limits { restart_backoff: Duration::from_millis(150), ..Limits::default() };
let waits: Vec<u128> = (1..=4).map(|n| limits.backoff(n).as_millis()).collect();
assert_eq!(waits, [150, 300, 600, 1200]);
assert_eq!(limits.backoff(30), Duration::from_millis(150 * 64), "the factor stops growing");
let long = Limits { restart_backoff: Duration::from_secs(10), ..Limits::default() };
assert_eq!(long.backoff(5), Duration::from_secs(60));
}
use super::*;
#[test]
+5 -1
Переглянути файл
@@ -659,6 +659,10 @@ mod maven_path_tests {
impl Subst {
fn new(target: &Path) -> Self {
// Tests run in parallel and may race for the same free letter; only a drive that
// shows this target's marker is ours.
let marker = format!("{}.subst", target.file_name().unwrap().to_string_lossy());
std::fs::write(target.join(&marker), "").unwrap();
for letter in (b'D'..=b'Z').rev() {
let name = format!("{}:", char::from(letter));
let root = PathBuf::from(format!("{name}\\"));
@@ -666,7 +670,7 @@ mod maven_path_tests {
continue;
}
let output = Command::new("subst").arg(&name).arg(target).output().unwrap();
if output.status.success() {
if output.status.success() && root.join(&marker).exists() {
return Self { name, root };
}
}
+1 -1
Переглянути файл
@@ -78,7 +78,7 @@ block2 = "0.6"
# Plugin secrets in the login keychain.
security-framework = "3.7"
objc2 = "0.6"
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSApplication", "NSButton", "NSResponder", "NSView", "NSWindow"] }
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSApplication", "NSButton", "NSResponder", "NSScreen", "NSView", "NSWindow"] }
objc2-core-foundation = { version = "0.3", default-features = false, features = ["std", "block2", "CFRunLoop"] }
objc2-foundation = { version = "0.3", default-features = false, features = ["std", "block2", "NSNotification", "NSOperation", "NSString"] }
# Used only by the debug font-restriction override; Cargo dependency cfg cannot test debug_assertions.
+1 -3
Переглянути файл
@@ -124,9 +124,7 @@ pub fn window_cycle(app: AppHandle, window: WebviewWindow, forward: bool) {
#[tauri::command]
#[specta::specta]
pub fn window_toggle_fullscreen(window: WebviewWindow) -> IdeResult<bool> {
let on = !window.is_fullscreen().map_err(|e| IdeError::internal(e.to_string()))?;
window.set_fullscreen(on).map_err(|e| IdeError::internal(e.to_string()))?;
Ok(on)
crate::window_groups::toggle_fullscreen(&window)
}
/// Height of the web title bar in native logical pixels (CSS height × IDE zoom).
+150 -1
Переглянути файл
@@ -2,7 +2,11 @@
use crate::windows::{Launch, WindowsState};
use ide_core::{IdeError, IdeResult};
use ide_workspace::window_groups::{TabbingPreference, should_group_new_project};
use objc2::{MainThreadMarker, rc::Retained, runtime::ProtocolObject};
use objc2::{
MainThreadMarker,
rc::Retained,
runtime::{AnyClass, AnyObject, Imp, ProtocolObject, Sel},
};
use objc2_app_kit::{NSWindow, NSWindowUserTabbingPreference};
use objc2_foundation::{NSNotificationCenter, NSObjectProtocol};
use tauri::{AppHandle, Manager, WebviewWindow};
@@ -96,3 +100,148 @@ pub fn transfer_fullscreen(from: &WebviewWindow, to: &WebviewWindow) -> tauri::R
native.toggleFullScreen(None);
})
}
/// Windows in simple fullscreen. Grouped project windows take turns in one Space; simple
/// fullscreen covers the screen without a Space of its own, so switching projects is a plain
/// show/hide instead of leaving one fullscreen Space and entering another.
static SIMPLE_FULLSCREEN: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
pub fn is_simple_fullscreen(label: &str) -> bool {
SIMPLE_FULLSCREEN.lock().unwrap().iter().any(|l| l == label)
}
pub fn set_simple_fullscreen(window: &WebviewWindow, on: bool) -> tauri::Result<()> {
if !on {
// Before the window goes back to its own frame.
let target = window.clone();
window.run_on_main_thread(move || keep_window_buttons(&target, false))?;
}
window.set_simple_fullscreen(on)?;
let any = {
let mut labels = SIMPLE_FULLSCREEN.lock().unwrap();
labels.retain(|l| l != window.label());
if on {
labels.push(window.label().to_owned());
}
!labels.is_empty()
};
let target = window.clone();
window.run_on_main_thread(move || {
present(any);
if on {
keep_window_buttons(&target, true);
}
})
}
thread_local! {
/// Minimum sizes of windows in simple fullscreen, restored when they leave it.
static MIN_SIZES: std::cell::RefCell<std::collections::HashMap<String, objc2_foundation::NSSize>> =
std::cell::RefCell::default();
}
/// Simple fullscreen drops the title bar and resizing; ours is transparent over the web toolbar,
/// so keep it and its buttons, the green one (enabled only for a resizable window) leading back
/// out of fullscreen. A minimum size of the whole screen keeps the edges from being dragged.
fn keep_window_buttons(window: &WebviewWindow, on: bool) {
use objc2_app_kit::NSWindowStyleMask;
let Ok(pointer) = window.ns_window() else { return };
let native = unsafe { &*pointer.cast::<NSWindow>() };
let label = window.label().to_owned();
if !on {
if let Some(size) = MIN_SIZES.with_borrow_mut(|sizes| sizes.remove(&label)) {
native.setMinSize(size);
}
return;
}
let Some(screen) = native.screen() else { return };
let frame = screen.frame();
MIN_SIZES.with_borrow_mut(|sizes| {
sizes.entry(label).or_insert_with(|| native.minSize());
});
native.setMinSize(frame.size);
native.setStyleMask(native.styleMask() | NSWindowStyleMask::Titled | NSWindowStyleMask::Resizable);
native.setFrame_display(frame, true);
}
/// Forgets a closed window; true when it was in simple fullscreen.
pub fn forget_simple_fullscreen(app: &AppHandle, label: &str) -> bool {
let (was, any) = {
let mut labels = SIMPLE_FULLSCREEN.lock().unwrap();
let before = labels.len();
labels.retain(|l| l != label);
(labels.len() != before, !labels.is_empty())
};
if was {
let label = label.to_owned();
let _ = app.run_on_main_thread(move || {
MIN_SIZES.with_borrow_mut(|sizes| sizes.remove(&label));
present(any);
});
}
was
}
/// Each window restores the presentation options it found on entering, which is wrong once
/// fullscreen has passed between windows; derive them from the windows in fullscreen instead.
fn present(fullscreen: bool) {
use objc2_app_kit::{NSApplication, NSApplicationPresentationOptions};
let Some(mtm) = MainThreadMarker::new() else { return };
let options = if fullscreen {
NSApplicationPresentationOptions::AutoHideDock | NSApplicationPresentationOptions::AutoHideMenuBar
} else {
NSApplicationPresentationOptions::Default
};
NSApplication::sharedApplication(mtm).setPresentationOptions(options);
}
type ToggleFullScreen = unsafe extern "C-unwind" fn(*mut AnyObject, Sel, *mut AnyObject);
static NATIVE_TOGGLE_FULLSCREEN: std::sync::OnceLock<ToggleFullScreen> = std::sync::OnceLock::new();
static APP: std::sync::OnceLock<AppHandle> = std::sync::OnceLock::new();
/// The green window button, the Globe-F shortcut and the system's Enter Full Screen item all
/// send `toggleFullScreen:`; a grouped window answers it with simple fullscreen instead.
pub fn intercept_toggle_fullscreen(window: &WebviewWindow) {
let _ = APP.set(window.app_handle().clone());
let _ = window.with_webview(|webview| unsafe {
let class = objc2::ffi::object_getClass(webview.ns_window().cast()) as *mut AnyClass;
let selector = objc2::sel!(toggleFullScreen:);
if NATIVE_TOGGLE_FULLSCREEN.get().is_some() {
return;
}
let Some(method) = (*class).instance_method(selector) else { return };
let native: ToggleFullScreen = std::mem::transmute(method.implementation());
let types = objc2::ffi::method_getTypeEncoding(method);
let _ = NATIVE_TOGGLE_FULLSCREEN.set(native);
let replacement: Imp = std::mem::transmute(toggle_fullscreen as ToggleFullScreen);
objc2::ffi::class_replaceMethod(class, selector, replacement, types);
});
}
unsafe extern "C-unwind" fn toggle_fullscreen(this: *mut AnyObject, selector: Sel, sender: *mut AnyObject) {
if let Some(window) = APP.get().and_then(|app| simple_fullscreen_window(app, this)) {
if let Err(error) = crate::window_groups::toggle_fullscreen(&window) {
tracing::warn!(message = error.message, "cannot toggle fullscreen");
}
return;
}
if let Some(native) = NATIVE_TOGGLE_FULLSCREEN.get() {
unsafe { native(this, selector, sender) };
}
}
/// `native` as a grouped project window (or one still in simple fullscreen) that is not in
/// native fullscreen; one in native fullscreen leaves it the usual way.
fn simple_fullscreen_window(app: &AppHandle, native: *mut AnyObject) -> Option<WebviewWindow> {
let mask: objc2_app_kit::NSWindowStyleMask = unsafe { objc2::msg_send![native, styleMask] };
if mask.contains(objc2_app_kit::NSWindowStyleMask::FullScreen) {
return None;
}
let window = app
.webview_windows()
.into_values()
.find(|w| w.ns_window().is_ok_and(|pointer| pointer.cast::<AnyObject>() == native))?;
let grouped = app.state::<WindowsState>().groups.lock().group(window.label()).is_some();
(grouped || is_simple_fullscreen(window.label())).then_some(window)
}
+71 -1
Переглянути файл
@@ -80,12 +80,61 @@ fn copy_frame(from: &WebviewWindow, to: &WebviewWindow) -> IdeResult<()> {
Ok(())
}
fn simple_fullscreen(label: &str) -> bool {
#[cfg(target_os = "macos")]
return crate::macos::is_simple_fullscreen(label);
#[cfg(not(target_os = "macos"))]
{
let _ = label;
false
}
}
#[cfg(target_os = "macos")]
fn set_simple_fullscreen(window: &WebviewWindow, on: bool) -> IdeResult<()> {
crate::macos::set_simple_fullscreen(window, on).map_err(|e| IdeError::internal(e.to_string()))
}
/// Fullscreen for `window`. On macOS a grouped window uses simple fullscreen, for every member
/// at once: the group stays in one Space and each member keeps the screen's size, so switching
/// projects is only showing one window and hiding the others.
pub fn toggle_fullscreen(window: &WebviewWindow) -> IdeResult<bool> {
let err = |e: tauri::Error| IdeError::internal(e.to_string());
#[cfg(target_os = "macos")]
{
let simple = simple_fullscreen(window.label());
let app = window.app_handle();
let members = app.state::<WindowsState>().groups.lock().group(window.label()).map(|g| g.members.clone());
if simple || (members.is_some() && !window.is_fullscreen().map_err(err)?) {
set_simple_fullscreen(window, !simple)?;
for member in members.iter().flatten().filter(|m| *m != window.label()) {
if let Some(other) = app.get_webview_window(member)
&& simple_fullscreen(member) == simple
{
set_simple_fullscreen(&other, !simple)?;
}
}
return Ok(!simple);
}
}
let on = !window.is_fullscreen().map_err(err)?;
window.set_fullscreen(on).map_err(err)?;
Ok(on)
}
pub fn select(app: &AppHandle, caller: &str, target: &str) -> IdeResult<()> {
let to = app.get_webview_window(target).ok_or_else(|| IdeError::not_found("Window closed"))?;
let state = app.state::<WindowsState>();
let previous = state.groups.lock().select(caller, target)?;
// In a fullscreen group the target already covers the screen, or does so before it is shown.
let simple = previous.selected != target && simple_fullscreen(&previous.selected);
let result = (|| {
if previous.selected != target
#[cfg(target_os = "macos")]
if simple && !simple_fullscreen(target) {
set_simple_fullscreen(&to, true)?;
}
if !simple
&& previous.selected != target
&& let Some(from) = app.get_webview_window(&previous.selected)
{
copy_frame(&from, &to)?;
@@ -137,6 +186,10 @@ pub fn merge(app: &AppHandle, caller: &str) -> IdeResult<()> {
// Native fullscreen puts each window in a separate Space; leave it before grouping.
for label in &members {
if let Some(window) = app.get_webview_window(label) {
#[cfg(target_os = "macos")]
if label != caller && simple_fullscreen(label) {
set_simple_fullscreen(&window, false)?;
}
window.set_fullscreen(false).map_err(|e| IdeError::internal(e.to_string()))?;
}
}
@@ -148,10 +201,21 @@ pub fn detach(app: &AppHandle, caller: &str) -> IdeResult<()> {
let state = app.state::<WindowsState>();
let next = state.groups.lock().detach(caller);
if let Some(next) = next {
// The tab that stays keeps the fullscreen; the detached window opens beside it.
#[cfg(target_os = "macos")]
let simple = simple_fullscreen(caller);
if let Some(window) = app.get_webview_window(&next) {
#[cfg(target_os = "macos")]
if simple && !simple_fullscreen(&next) {
set_simple_fullscreen(&window, true)?;
}
window.show().map_err(|e| IdeError::internal(e.to_string()))?;
}
if let Some(window) = app.get_webview_window(caller) {
#[cfg(target_os = "macos")]
if simple {
set_simple_fullscreen(&window, false)?;
}
if let Ok(position) = window.outer_position() {
let _ = window.set_position(tauri::PhysicalPosition::new(position.x + 32, position.y + 32));
}
@@ -164,9 +228,15 @@ pub fn detach(app: &AppHandle, caller: &str) -> IdeResult<()> {
pub fn destroyed(app: &AppHandle, caller: &str) {
let Some(state) = app.try_state::<WindowsState>() else { return };
#[cfg(target_os = "macos")]
let simple = crate::macos::forget_simple_fullscreen(app, caller);
let next = state.groups.lock().detach(caller);
if !state.quitting() {
if let Some(window) = next.and_then(|label| app.get_webview_window(&label)) {
#[cfg(target_os = "macos")]
if simple && !simple_fullscreen(window.label()) {
let _ = set_simple_fullscreen(&window, true);
}
windows::focus(&window);
}
let app = app.clone();
+2
Переглянути файл
@@ -602,6 +602,8 @@ fn create_window_for(
app.state::<WindowsState>().set_launch(&label, launch);
let window = build_project_window(app, config)?;
#[cfg(target_os = "macos")]
crate::macos::intercept_toggle_fullscreen(&window);
#[cfg(target_os = "macos")]
if let Some(target) = tab_target {
crate::window_groups::join(app, target.label(), window.label())?;
return Ok(window);