fix(workbench): Reset project state when a window switches projects

Opening another project in the same window left the previous project's state in
module-level stores: Amend and the commit message carried over, debug sessions kept
running, and Git Log, usages, hierarchy, inspection, HTTP client, recent locations,
navigation history and notifications still showed the old project.

Reset each of them on a project root change, stop the old debug sessions, ask about
unsaved changes before leaving a project, close the settings window (it would apply
to the new project) and end the indexing task when a scan is cancelled.
Цей коміт міститься в:
l0ng-ai committed 2026-10-22 20:26:04 +08:00
1 джерело 9a2025b76e
коміт 5f6e2a9c85
30 files changed
+216 -26

No files matched your search

+5
Переглянути файл
@@ -56,6 +56,10 @@ pub async fn open_project(window: Window, path: PathBuf) -> IdeResult<ProjectInf
// Opening touches the disk (index cache, watcher, git): keep it off the async runtime threads.
let app = window.app_handle().clone();
let label = window.label().to_owned();
// Replacing this window's project (the UI skips reopening the same one).
if app.state::<AppState>().project(&label).is_ok() {
crate::windows::close_settings_window(&app, &label);
}
let project = tauri::async_runtime::spawn_blocking(move || app.state::<AppState>().open_project(&label, &path))
.await
.map_err(|e| IdeError::internal(e.to_string()))??;
@@ -76,6 +80,7 @@ fn project_info(project: &crate::state::Project) -> ProjectInfo {
#[tauri::command]
#[specta::specta]
pub fn close_project(window: Window, state: State<'_, AppState>) {
crate::windows::close_settings_window(window.app_handle(), window.label());
state.close_project(window.label());
}
+7
Переглянути файл
@@ -108,6 +108,13 @@ pub fn settings_label(parent: &str) -> String {
format!("{SETTINGS_PREFIX}{parent}")
}
/// Closes `parent`'s settings window: it shows (and would apply to) the project the parent is leaving.
pub fn close_settings_window(app: &AppHandle, parent: &str) {
if let Some(w) = app.get_webview_window(&settings_label(parent)) {
let _ = w.close();
}
}
/// Project windows (everything but settings windows), for counting and cycling.
pub fn project_window_labels(app: &AppHandle) -> Vec<String> {
sorted_labels(app.webview_windows().keys().map(String::as_str).filter(|l| !is_settings_window(l)))