onboarding: Show indication that settings have already been imported (#35615)

Co-Authored-By: Danilo <danilo@zed.dev>
Co-Authored-By: Anthony <anthony@zed.dev>

Release Notes:

- N/A
This commit is contained in:
Ben Kunkle 2025-08-04 19:01:53 -05:00 committed by GitHub
parent e1d0e3fc34
commit 06226e1cbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 192 additions and 90 deletions

View file

@ -2,7 +2,11 @@ use anyhow::{Context as _, Result};
use collections::{BTreeMap, HashMap, btree_map, hash_map};
use ec4rs::{ConfigParser, PropertiesSource, Section};
use fs::Fs;
use futures::{FutureExt, StreamExt, channel::mpsc, future::LocalBoxFuture};
use futures::{
FutureExt, StreamExt,
channel::{mpsc, oneshot},
future::LocalBoxFuture,
};
use gpui::{App, AsyncApp, BorrowAppContext, Global, Task, UpdateGlobal};
use paths::{EDITORCONFIG_NAME, local_settings_file_relative_path, task_file_name};
@ -531,39 +535,60 @@ impl SettingsStore {
.ok();
}
pub fn import_vscode_settings(&self, fs: Arc<dyn Fs>, vscode_settings: VsCodeSettings) {
pub fn import_vscode_settings(
&self,
fs: Arc<dyn Fs>,
vscode_settings: VsCodeSettings,
) -> oneshot::Receiver<Result<()>> {
let (tx, rx) = oneshot::channel::<Result<()>>();
self.setting_file_updates_tx
.unbounded_send(Box::new(move |cx: AsyncApp| {
async move {
let old_text = Self::load_settings(&fs).await?;
let new_text = cx.read_global(|store: &SettingsStore, _cx| {
store.get_vscode_edits(old_text, &vscode_settings)
})?;
let settings_path = paths::settings_file().as_path();
if fs.is_file(settings_path).await {
let resolved_path =
fs.canonicalize(settings_path).await.with_context(|| {
format!("Failed to canonicalize settings path {:?}", settings_path)
})?;
let res = async move {
let old_text = Self::load_settings(&fs).await?;
let new_text = cx.read_global(|store: &SettingsStore, _cx| {
store.get_vscode_edits(old_text, &vscode_settings)
})?;
let settings_path = paths::settings_file().as_path();
if fs.is_file(settings_path).await {
let resolved_path =
fs.canonicalize(settings_path).await.with_context(|| {
format!(
"Failed to canonicalize settings path {:?}",
settings_path
)
})?;
fs.atomic_write(resolved_path.clone(), new_text)
.await
.with_context(|| {
format!("Failed to write settings to file {:?}", resolved_path)
})?;
} else {
fs.atomic_write(settings_path.to_path_buf(), new_text)
.await
.with_context(|| {
format!("Failed to write settings to file {:?}", settings_path)
})?;
fs.atomic_write(resolved_path.clone(), new_text)
.await
.with_context(|| {
format!("Failed to write settings to file {:?}", resolved_path)
})?;
} else {
fs.atomic_write(settings_path.to_path_buf(), new_text)
.await
.with_context(|| {
format!("Failed to write settings to file {:?}", settings_path)
})?;
}
anyhow::Ok(())
}
.await;
anyhow::Ok(())
let new_res = match &res {
Ok(_) => anyhow::Ok(()),
Err(e) => Err(anyhow::anyhow!("Failed to write settings to file {:?}", e)),
};
_ = tx.send(new_res);
res
}
.boxed_local()
}))
.ok();
rx
}
}