From 7687e1f390f60df7b2144510911248a0ec6cd86a Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Fri, 13 Feb 2026 19:54:10 +0800 Subject: [PATCH] settings: Await config worktree before opening settings.json (#47199) Closes #47007 Release Notes: - Fixed await config worktree before opening settings.json ensures that the worktree creation is awaited before attempting to open the settings file. Signed-off-by: Xiaobo Liu --- crates/zed/src/zed.rs | 59 ++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index c790a410585a6d439ab5e33c28a69cecd926ac44..78ca459ad8cf0befb313914acf1456a82939ca42 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -2062,39 +2062,40 @@ fn open_settings_file( cx: &mut Context, ) { cx.spawn_in(window, async move |workspace, cx| { - let (worktree_creation_task, settings_open_task) = workspace + let settings_open_task = workspace .update_in(cx, |workspace, window, cx| { - workspace.with_local_or_wsl_workspace(window, cx, move |workspace, window, cx| { - let project = workspace.project().clone(); - - let worktree_creation_task = cx.spawn_in(window, async move |_, cx| { - let config_dir = project - .update(cx, |project, cx| { - project.try_windows_path_to_wsl(paths::config_dir().as_path(), cx) - }) - .await?; - // Set up a dedicated worktree for settings, since - // otherwise we're dropping and re-starting LSP servers - // for each file inside on every settings file - // close/open - - // TODO: Do note that all other external files (e.g. - // drag and drop from OS) still have their worktrees - // released on file close, causing LSP servers' - // restarts. - project - .update(cx, |project, cx| { - project.find_or_create_worktree(&config_dir, false, cx) - }) - .await - }); - let settings_open_task = - create_and_open_local_file(abs_path, window, cx, default_content); - (worktree_creation_task, settings_open_task) + workspace.with_local_workspace(window, cx, move |_workspace, window, cx| { + cx.spawn_in(window, async move |workspace, cx| { + let worktree_creation_task = + workspace.update_in(cx, |workspace, _window, cx| { + workspace.project().update(cx, |project, cx| { + // Set up a dedicated worktree for settings, since + // otherwise we're dropping and re-starting LSP servers + // for each file inside on every settings file + // close/open + + // TODO: Do note that all other external files (e.g. + // drag and drop from OS) still have their worktrees + // released on file close, causing LSP servers' + // restarts. + project.find_or_create_worktree( + paths::config_dir().as_path(), + false, + cx, + ) + }) + })?; + let _ = worktree_creation_task.await?; + let settings_open_task = + workspace.update_in(cx, |_workspace, window, cx| { + create_and_open_local_file(abs_path, window, cx, default_content) + })?; + let _ = settings_open_task.await?; + anyhow::Ok(()) + }) }) })? .await?; - let _ = worktree_creation_task.await?; let _ = settings_open_task.await?; anyhow::Ok(()) })