VSCode Settings import (#29018)
Things this doesn't currently handle: - [x] ~testing~ - ~we really need an snapshot test that takes a vscode settings file with all options that we support, and verifies the zed settings file you get from importing it, both from an empty starting file or one with lots of conflicts. that way we can open said vscode settings file in vscode to ensure that those options all still exist in the future.~ - Discussed this, we don't think this will meaningfully protect us from future failures, and we will just do this as a manual validation step before merging this PR. Any imports that have meaningfully complex translation steps should still be tested. - [x] confirmation (right now it just clobbers your settings file silently) - it'd be really cool if we could show a diff multibuffer of your current settings with the result of the vscode import and let you pick "hunks" to keep, but that's probably too much effort for this feature, especially given that we expect most of the people using it to have an empty/barebones zed config when they run the import. - [x] ~UI in the "welcome" page~ - we're planning on redoing our welcome/walkthrough experience anyways, but in the meantime it'd be nice to conditionally show a button there if we see a user level vscode config - we'll add it to the UI when we land the new walkthrough experience, for now it'll be accessible through the action - [ ] project-specific settings - handling translation of `.vscode/settings.json` or `.code-workspace` settings to `.zed/settings.json` will come in a future PR, along with UI to prompt the user for those actions when opening a project with local vscode settings for the first time - [ ] extension settings - we probably want to do a best-effort pass of popular extensions like vim and git lens - it's also possible to look for installed/enabled extensions with `code --list-extensions`, but we'd have to maintain some sort of mapping of those to our settings and/or extensions - [ ] LSP settings - these are tricky without access to the json schemas for various language server extensions. we could probably manage to do translations for a couple popular languages and avoid solving it in the general case. - [ ] platform specific settings (`[macos].blah`) - this is blocked on #16392 which I'm hoping to address soon - [ ] language specific settings (`[rust].foo`) - totally doable, just haven't gotten to it yet ~We may want to put this behind some kind of flag and/or not land it until some of the above issues are addressed, given that we expect people to only run this importer once there's an incentive to get it right the first time. Maybe we land it alongside a keymap importer so you don't have to go through separate imports for those?~ We are gonna land this as-is, all these unchecked items at the bottom will be addressed in followup PRs, so maybe don't run the importer for now if you have a large and complex VsCode settings file you'd like to import. Release Notes: - Added a VSCode settings importer, available via a `zed::ImportVsCodeSettings` action --------- Co-authored-by: Mikayla Maki <mikayla@zed.dev> Co-authored-by: Kirill Bulatov <kirill@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
parent
40b5a1b028
commit
f11c749353
41 changed files with 1383 additions and 137 deletions
|
@ -255,6 +255,70 @@ impl settings::Settings for TerminalSettings {
|
|||
|
||||
root_schema
|
||||
}
|
||||
|
||||
fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
|
||||
let name = |s| format!("terminal.integrated.{s}");
|
||||
|
||||
vscode.f32_setting(&name("fontSize"), &mut current.font_size);
|
||||
vscode.string_setting(&name("fontFamily"), &mut current.font_family);
|
||||
vscode.bool_setting(&name("copyOnSelection"), &mut current.copy_on_select);
|
||||
vscode.bool_setting("macOptionIsMeta", &mut current.option_as_meta);
|
||||
vscode.usize_setting("scrollback", &mut current.max_scroll_history_lines);
|
||||
match vscode.read_bool(&name("cursorBlinking")) {
|
||||
Some(true) => current.blinking = Some(TerminalBlink::On),
|
||||
Some(false) => current.blinking = Some(TerminalBlink::Off),
|
||||
None => {}
|
||||
}
|
||||
vscode.enum_setting(
|
||||
&name("cursorStyle"),
|
||||
&mut current.cursor_shape,
|
||||
|s| match s {
|
||||
"block" => Some(CursorShape::Block),
|
||||
"line" => Some(CursorShape::Bar),
|
||||
"underline" => Some(CursorShape::Underline),
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
// they also have "none" and "outline" as options but just for the "Inactive" variant
|
||||
if let Some(height) = vscode
|
||||
.read_value(&name("lineHeight"))
|
||||
.and_then(|v| v.as_f64())
|
||||
{
|
||||
current.line_height = Some(TerminalLineHeight::Custom(height as f32))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let platform = "windows";
|
||||
#[cfg(target_os = "linux")]
|
||||
let platform = "linux";
|
||||
#[cfg(target_os = "macos")]
|
||||
let platform = "osx";
|
||||
|
||||
// TODO: handle arguments
|
||||
let shell_name = format!("{platform}Exec");
|
||||
if let Some(s) = vscode.read_string(&name(&shell_name)) {
|
||||
current.shell = Some(Shell::Program(s.to_owned()))
|
||||
}
|
||||
|
||||
if let Some(env) = vscode
|
||||
.read_value(&name(&format!("env.{platform}")))
|
||||
.and_then(|v| v.as_object())
|
||||
{
|
||||
for (k, v) in env {
|
||||
if v.is_null() {
|
||||
if let Some(zed_env) = current.env.as_mut() {
|
||||
zed_env.remove(k);
|
||||
}
|
||||
}
|
||||
let Some(v) = v.as_str() else { continue };
|
||||
if let Some(zed_env) = current.env.as_mut() {
|
||||
zed_env.insert(k.clone(), v.to_owned());
|
||||
} else {
|
||||
current.env = Some([(k.clone(), v.to_owned())].into_iter().collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue