Improve logic for finding VSCode / Cursor settings files (#32721)
* Fixes a bug where for Cursor, `config_dir()` (Zed's config dir) was being used instead of `dirs::config_dir` (`~/.config` / `$XDG_CONFIG_HOME`). * Adds support for windows, before it was using the user profile folder + `/.config` which is incorrect. * Now looks using a variety of product names - `["Code", "Code - OSS", "Code Dev", "Code - OSS Dev", "code-oss-dev", "VSCodium"]`. * Now shows settings path that was read before confirming import. Including this path in the confirmation modal is a bit ugly (making it link-styled and clickable would be nice), but I think it's better to include it now that it is selecting the first match of a list of candidate paths:  Release Notes: - Added more settings file locations to check for VS Code / Cursor settings import.
This commit is contained in:
@@ -15,6 +15,7 @@ use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use settings::{SettingsStore, VsCodeSettingsSource};
|
||||
use ui::prelude::*;
|
||||
use util::truncate_and_remove_front;
|
||||
use workspace::item::{Item, ItemEvent};
|
||||
use workspace::{Workspace, with_active_or_new_workspace};
|
||||
|
||||
@@ -129,33 +130,32 @@ async fn handle_import_vscode_settings(
|
||||
fs: Arc<dyn Fs>,
|
||||
cx: &mut AsyncWindowContext,
|
||||
) {
|
||||
let vscode = match settings::VsCodeSettings::load_user_settings(source, fs.clone()).await {
|
||||
Ok(vscode) => vscode,
|
||||
Err(err) => {
|
||||
println!(
|
||||
"Failed to load {source} settings: {}",
|
||||
err.context(format!(
|
||||
"Loading {source} settings from path: {:?}",
|
||||
paths::vscode_settings_file()
|
||||
))
|
||||
);
|
||||
|
||||
let _ = cx.prompt(
|
||||
gpui::PromptLevel::Info,
|
||||
&format!("Could not find or load a {source} settings file"),
|
||||
None,
|
||||
&["Ok"],
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let vscode_settings =
|
||||
match settings::VsCodeSettings::load_user_settings(source, fs.clone()).await {
|
||||
Ok(vscode_settings) => vscode_settings,
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
let _ = cx.prompt(
|
||||
gpui::PromptLevel::Info,
|
||||
&format!("Could not find or load a {source} settings file"),
|
||||
None,
|
||||
&["Ok"],
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let prompt = if skip_prompt {
|
||||
Task::ready(Some(0))
|
||||
} else {
|
||||
let prompt = cx.prompt(
|
||||
gpui::PromptLevel::Warning,
|
||||
"Importing settings may overwrite your existing settings",
|
||||
&format!(
|
||||
"Importing {} settings may overwrite your existing settings. \
|
||||
Will import settings from {}",
|
||||
vscode_settings.source,
|
||||
truncate_and_remove_front(&vscode_settings.path.to_string_lossy(), 128),
|
||||
),
|
||||
None,
|
||||
&["Ok", "Cancel"],
|
||||
);
|
||||
@@ -166,9 +166,11 @@ async fn handle_import_vscode_settings(
|
||||
}
|
||||
|
||||
cx.update(|_, cx| {
|
||||
let source = vscode_settings.source;
|
||||
let path = vscode_settings.path.clone();
|
||||
cx.global::<SettingsStore>()
|
||||
.import_vscode_settings(fs, vscode);
|
||||
log::info!("Imported settings from {source}");
|
||||
.import_vscode_settings(fs, vscode_settings);
|
||||
log::info!("Imported {source} settings from {}", path.display());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user