VSCode settings import refactor (#40513)
A small follow-up to the settings refactor of a few weeks ago to move all the VSCode settings imports to one place. This should make it easier to spot missing imports, and easier to test the importer. Release Notes: - N/A
This commit is contained in:
@@ -76,40 +76,6 @@ impl Settings for ItemSettings {
|
||||
show_close_button: tabs.show_close_button.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
) {
|
||||
if let Some(b) = vscode.read_bool("workbench.editor.tabActionCloseVisibility") {
|
||||
current.tabs.get_or_insert_default().show_close_button = Some(if b {
|
||||
ShowCloseButton::Always
|
||||
} else {
|
||||
ShowCloseButton::Hidden
|
||||
})
|
||||
}
|
||||
if let Some(s) = vscode.read_enum("workbench.editor.tabActionLocation", |s| match s {
|
||||
"right" => Some(ClosePosition::Right),
|
||||
"left" => Some(ClosePosition::Left),
|
||||
_ => None,
|
||||
}) {
|
||||
current.tabs.get_or_insert_default().close_position = Some(s)
|
||||
}
|
||||
if let Some(b) = vscode.read_bool("workbench.editor.focusRecentEditorAfterClose") {
|
||||
current.tabs.get_or_insert_default().activate_on_close = Some(if b {
|
||||
ActivateOnClose::History
|
||||
} else {
|
||||
ActivateOnClose::LeftNeighbour
|
||||
})
|
||||
}
|
||||
|
||||
if let Some(b) = vscode.read_bool("workbench.editor.showIcons") {
|
||||
current.tabs.get_or_insert_default().file_icons = Some(b);
|
||||
};
|
||||
if let Some(b) = vscode.read_bool("git.decorations.enabled") {
|
||||
current.tabs.get_or_insert_default().git_status = Some(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings for PreviewTabsSettings {
|
||||
@@ -123,31 +89,6 @@ impl Settings for PreviewTabsSettings {
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
) {
|
||||
if let Some(enabled) = vscode.read_bool("workbench.editor.enablePreview") {
|
||||
current.preview_tabs.get_or_insert_default().enabled = Some(enabled);
|
||||
}
|
||||
if let Some(enable_preview_from_code_navigation) =
|
||||
vscode.read_bool("workbench.editor.enablePreviewFromCodeNavigation")
|
||||
{
|
||||
current
|
||||
.preview_tabs
|
||||
.get_or_insert_default()
|
||||
.enable_preview_from_code_navigation = Some(enable_preview_from_code_navigation)
|
||||
}
|
||||
if let Some(enable_preview_from_file_finder) =
|
||||
vscode.read_bool("workbench.editor.enablePreviewFromQuickOpen")
|
||||
{
|
||||
current
|
||||
.preview_tabs
|
||||
.get_or_insert_default()
|
||||
.enable_preview_from_file_finder = Some(enable_preview_from_file_finder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
|
||||
|
||||
@@ -108,91 +108,6 @@ impl Settings for WorkspaceSettings {
|
||||
zoomed_padding: workspace.zoomed_padding.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
) {
|
||||
if vscode
|
||||
.read_bool("accessibility.dimUnfocused.enabled")
|
||||
.unwrap_or_default()
|
||||
&& let Some(opacity) = vscode
|
||||
.read_value("accessibility.dimUnfocused.opacity")
|
||||
.and_then(|v| v.as_f64())
|
||||
{
|
||||
current
|
||||
.workspace
|
||||
.active_pane_modifiers
|
||||
.get_or_insert_default()
|
||||
.inactive_opacity = Some(opacity as f32);
|
||||
}
|
||||
|
||||
vscode.enum_setting(
|
||||
"window.confirmBeforeClose",
|
||||
&mut current.workspace.confirm_quit,
|
||||
|s| match s {
|
||||
"always" | "keyboardOnly" => Some(true),
|
||||
"never" => Some(false),
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
|
||||
vscode.bool_setting(
|
||||
"workbench.editor.restoreViewState",
|
||||
&mut current.workspace.restore_on_file_reopen,
|
||||
);
|
||||
|
||||
if let Some(b) = vscode.read_bool("window.closeWhenEmpty") {
|
||||
current.workspace.when_closing_with_no_tabs = Some(if b {
|
||||
settings::CloseWindowWhenNoItems::CloseWindow
|
||||
} else {
|
||||
settings::CloseWindowWhenNoItems::KeepWindowOpen
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(b) = vscode.read_bool("files.simpleDialog.enable") {
|
||||
current.workspace.use_system_path_prompts = Some(!b);
|
||||
}
|
||||
|
||||
if let Some(v) = vscode.read_enum("files.autoSave", |s| match s {
|
||||
"off" => Some(AutosaveSetting::Off),
|
||||
"afterDelay" => Some(AutosaveSetting::AfterDelay {
|
||||
milliseconds: vscode
|
||||
.read_value("files.autoSaveDelay")
|
||||
.and_then(|v| v.as_u64())
|
||||
.unwrap_or(1000),
|
||||
}),
|
||||
"onFocusChange" => Some(AutosaveSetting::OnFocusChange),
|
||||
"onWindowChange" => Some(AutosaveSetting::OnWindowChange),
|
||||
_ => None,
|
||||
}) {
|
||||
current.workspace.autosave = Some(v);
|
||||
}
|
||||
|
||||
// workbench.editor.limit contains "enabled", "value", and "perEditorGroup"
|
||||
// our semantics match if those are set to true, some N, and true respectively.
|
||||
// we'll ignore "perEditorGroup" for now since we only support a global max
|
||||
if let Some(n) = vscode
|
||||
.read_value("workbench.editor.limit.value")
|
||||
.and_then(|v| v.as_u64())
|
||||
.and_then(|n| NonZeroUsize::new(n as usize))
|
||||
&& vscode
|
||||
.read_bool("workbench.editor.limit.enabled")
|
||||
.unwrap_or_default()
|
||||
{
|
||||
current.workspace.max_tabs = Some(n)
|
||||
}
|
||||
|
||||
if let Some(b) = vscode.read_bool("window.nativeTabs") {
|
||||
current.workspace.use_system_window_tabs = Some(b);
|
||||
}
|
||||
|
||||
// some combination of "window.restoreWindows" and "workbench.startupEditor" might
|
||||
// map to our "restore_on_startup"
|
||||
|
||||
// there doesn't seem to be a way to read whether the bottom dock's "justified"
|
||||
// setting is enabled in vscode. that'd be our equivalent to "bottom_dock_layout"
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings for TabBarSettings {
|
||||
@@ -204,22 +119,6 @@ impl Settings for TabBarSettings {
|
||||
show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
) {
|
||||
if let Some(b) = vscode.read_enum("workbench.editor.showTabs", |s| match s {
|
||||
"multiple" => Some(true),
|
||||
"single" | "none" => Some(false),
|
||||
_ => None,
|
||||
}) {
|
||||
current.tab_bar.get_or_insert_default().show = Some(b);
|
||||
}
|
||||
if Some("hidden") == vscode.read_string("workbench.editor.editorActionsLocation") {
|
||||
current.tab_bar.get_or_insert_default().show_tab_bar_buttons = Some(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -238,13 +137,4 @@ impl Settings for StatusBarSettings {
|
||||
cursor_position_button: status_bar.cursor_position_button.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(
|
||||
vscode: &settings::VsCodeSettings,
|
||||
current: &mut settings::SettingsContent,
|
||||
) {
|
||||
if let Some(show) = vscode.read_bool("workbench.statusBar.visible") {
|
||||
current.status_bar.get_or_insert_default().show = Some(show);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user