Revert "settings: Remove auxiliary Content types where possible (#16744)" (#17768)

This breaks setting `{"scrollbar": {"show":"never"}}`
Release Notes:

- N/A
This commit is contained in:
Conrad Irwin
2024-09-12 14:46:08 -04:00
committed by GitHub
parent 3b37db4140
commit 4d26f83d23
49 changed files with 686 additions and 833 deletions
+2 -2
View File
@@ -10640,7 +10640,7 @@ impl Editor {
let fs = workspace.read(cx).app_state().fs.clone();
let current_show = TabBarSettings::get_global(cx).show;
update_settings_file::<TabBarSettings>(fs, cx, move |setting, _| {
setting.show = !current_show;
setting.show = Some(!current_show);
});
}
@@ -12563,7 +12563,7 @@ impl EditorSnapshot {
let show_git_gutter = self.show_git_diff_gutter.unwrap_or_else(|| {
matches!(
ProjectSettings::get_global(cx).git.git_gutter,
GitGutterSetting::TrackedFiles
Some(GitGutterSetting::TrackedFiles)
)
});
let gutter_settings = EditorSettings::get_global(cx).gutter;
+194 -124
View File
@@ -3,105 +3,38 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
#[derive(Deserialize, Clone)]
pub struct EditorSettings {
/// Whether the cursor blinks in the editor.
pub cursor_blink: bool,
/// How to highlight the current line in the editor.
pub current_line_highlight: CurrentLineHighlight,
/// Whether to show the informational hover box when moving the mouse
/// over symbols in the editor.
pub hover_popover_enabled: bool,
/// Whether to pop the completions menu while typing in an editor without
/// explicitly requesting it.
pub show_completions_on_input: bool,
/// Whether to display inline and alongside documentation for items in the
/// completions menu.
pub show_completion_documentation: bool,
/// The debounce delay before re-querying the language server for completion
/// documentation when not included in original completion list.
pub completion_documentation_secondary_query_debounce: u64,
/// Whether to use additional LSP queries to format (and amend) the code after
/// every "trigger" symbol input, defined by LSP server capabilities.
pub use_on_type_format: bool,
/// Toolbar related settings
pub toolbar: Toolbar,
/// Scrollbar related settings
pub scrollbar: Scrollbar,
/// Gutter related settings
pub gutter: Gutter,
/// Whether the editor will scroll beyond the last line.
pub scroll_beyond_last_line: ScrollBeyondLastLine,
/// The number of lines to keep above/below the cursor when auto-scrolling.
pub vertical_scroll_margin: f32,
/// Scroll sensitivity multiplier. This multiplier is applied
/// to both the horizontal and vertical delta values while scrolling.
pub scroll_sensitivity: f32,
/// Whether the line numbers on editors gutter are relative or not.
pub relative_line_numbers: bool,
/// When to populate a new search's query based on the text under the cursor.
pub seed_search_query_from_cursor: SeedQuerySetting,
pub use_smartcase_search: bool,
/// The key to use for adding multiple cursors
pub multi_cursor_modifier: MultiCursorModifier,
/// Hide the values of variables in `private` files, as defined by the
/// private_files setting. This only changes the visual representation,
/// the values are still present in the file and can be selected / copied / pasted
pub redact_private_values: bool,
/// How many lines to expand the multibuffer excerpts by default
pub expand_excerpt_lines: u32,
pub middle_click_paste: bool,
/// What to do when multibuffer is double clicked in some of its excerpts
/// (parts of singleton buffers).
#[serde(default)]
pub double_click_in_multibuffer: DoubleClickInMultibuffer,
/// Whether the editor search results will loop
pub search_wrap: bool,
#[serde(default)]
pub search: SearchSettings,
/// Show method signatures in the editor, when inside parentheses.
pub auto_signature_help: bool,
/// Whether to show the signature help after completion or a bracket pair inserted.
/// If `auto_signature_help` is enabled, this setting will be treated as enabled also.
pub show_signature_help_after_edits: bool,
/// Jupyter REPL settings.
pub jupyter: Jupyter,
}
impl Default for EditorSettings {
fn default() -> Self {
Self {
cursor_blink: true,
current_line_highlight: CurrentLineHighlight::All,
hover_popover_enabled: true,
show_completions_on_input: true,
show_completion_documentation: true,
completion_documentation_secondary_query_debounce: 300,
use_on_type_format: true,
toolbar: Default::default(),
scrollbar: Default::default(),
gutter: Default::default(),
scroll_beyond_last_line: ScrollBeyondLastLine::OnePage,
vertical_scroll_margin: 3.,
scroll_sensitivity: 1.0,
relative_line_numbers: false,
seed_search_query_from_cursor: SeedQuerySetting::Always,
multi_cursor_modifier: MultiCursorModifier::Alt,
redact_private_values: false,
expand_excerpt_lines: 3,
double_click_in_multibuffer: DoubleClickInMultibuffer::Select,
search_wrap: true,
auto_signature_help: false,
show_signature_help_after_edits: true,
jupyter: Default::default(),
use_smartcase_search: false,
middle_click_paste: true,
search: SearchSettings::default(),
}
}
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CurrentLineHighlight {
@@ -139,93 +72,48 @@ pub enum DoubleClickInMultibuffer {
Open,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[derive(Debug, Clone, Deserialize)]
pub struct Jupyter {
/// Whether the Jupyter feature is enabled.
///
/// Default: true
pub enabled: bool,
}
impl Default for Jupyter {
fn default() -> Self {
Self { enabled: true }
}
#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct JupyterContent {
/// Whether the Jupyter feature is enabled.
///
/// Default: true
pub enabled: Option<bool>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(default)]
pub struct Toolbar {
/// Whether to display breadcrumbs in the editor toolbar.
pub breadcrumbs: bool,
/// Whether to display quick action buttons in the editor toolbar.
pub quick_actions: bool,
/// Whether to show the selections menu in the editor toolbar
pub selections_menu: bool,
}
impl Default for Toolbar {
fn default() -> Self {
Self {
breadcrumbs: true,
quick_actions: true,
selections_menu: true,
}
}
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct Scrollbar {
/// When to show the scrollbar in the editor.
pub show: ShowScrollbar,
/// Whether to show git diff indicators in the scrollbar.
pub git_diff: bool,
/// Whether to show buffer search result indicators in the scrollbar.
pub selected_symbol: bool,
/// Whether to show selected symbol occurrences in the scrollbar.
pub search_results: bool,
/// Whether to show diagnostic indicators in the scrollbar.
pub diagnostics: bool,
/// Whether to show cursor positions in the scrollbar.
pub cursors: bool,
}
impl Default for Scrollbar {
fn default() -> Self {
Self {
show: ShowScrollbar::Auto,
git_diff: true,
selected_symbol: true,
search_results: true,
diagnostics: true,
cursors: true,
}
}
}
/// Gutter-related settings.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(default)]
pub struct Gutter {
/// Whether to show line numbers in the gutter.
pub line_numbers: bool,
/// Whether to show code action buttons in the gutter.
pub code_actions: bool,
/// Whether to show runnable buttons in the gutter.
pub runnables: bool,
/// Whether to show fold buttons in the gutter.
pub folds: bool,
}
impl Default for Gutter {
fn default() -> Self {
Self {
line_numbers: true,
code_actions: true,
runnables: true,
folds: true,
}
}
}
/// When to show the scrollbar in the editor.
///
/// Default: auto
@@ -283,6 +171,188 @@ pub struct SearchSettings {
pub regex: bool,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct EditorSettingsContent {
/// Whether the cursor blinks in the editor.
///
/// Default: true
pub cursor_blink: Option<bool>,
/// How to highlight the current line in the editor.
///
/// Default: all
pub current_line_highlight: Option<CurrentLineHighlight>,
/// Whether to show the informational hover box when moving the mouse
/// over symbols in the editor.
///
/// Default: true
pub hover_popover_enabled: Option<bool>,
/// Whether to pop the completions menu while typing in an editor without
/// explicitly requesting it.
///
/// Default: true
pub show_completions_on_input: Option<bool>,
/// Whether to display inline and alongside documentation for items in the
/// completions menu.
///
/// Default: true
pub show_completion_documentation: Option<bool>,
/// The debounce delay before re-querying the language server for completion
/// documentation when not included in original completion list.
///
/// Default: 300 ms
pub completion_documentation_secondary_query_debounce: Option<u64>,
/// Whether to use additional LSP queries to format (and amend) the code after
/// every "trigger" symbol input, defined by LSP server capabilities.
///
/// Default: true
pub use_on_type_format: Option<bool>,
/// Toolbar related settings
pub toolbar: Option<ToolbarContent>,
/// Scrollbar related settings
pub scrollbar: Option<ScrollbarContent>,
/// Gutter related settings
pub gutter: Option<GutterContent>,
/// Whether the editor will scroll beyond the last line.
///
/// Default: one_page
pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
/// The number of lines to keep above/below the cursor when auto-scrolling.
///
/// Default: 3.
pub vertical_scroll_margin: Option<f32>,
/// Scroll sensitivity multiplier. This multiplier is applied
/// to both the horizontal and vertical delta values while scrolling.
///
/// Default: 1.0
pub scroll_sensitivity: Option<f32>,
/// Whether the line numbers on editors gutter are relative or not.
///
/// Default: false
pub relative_line_numbers: Option<bool>,
/// When to populate a new search's query based on the text under the cursor.
///
/// Default: always
pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
pub use_smartcase_search: Option<bool>,
/// The key to use for adding multiple cursors
///
/// Default: alt
pub multi_cursor_modifier: Option<MultiCursorModifier>,
/// Hide the values of variables in `private` files, as defined by the
/// private_files setting. This only changes the visual representation,
/// the values are still present in the file and can be selected / copied / pasted
///
/// Default: false
pub redact_private_values: Option<bool>,
/// How many lines to expand the multibuffer excerpts by default
///
/// Default: 3
pub expand_excerpt_lines: Option<u32>,
/// Whether to enable middle-click paste on Linux
///
/// Default: true
pub middle_click_paste: Option<bool>,
/// What to do when multibuffer is double clicked in some of its excerpts
/// (parts of singleton buffers).
///
/// Default: select
pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
/// Whether the editor search results will loop
///
/// Default: true
pub search_wrap: Option<bool>,
/// Defaults to use when opening a new buffer and project search items.
///
/// Default: nothing is enabled
pub search: Option<SearchSettings>,
/// Whether to automatically show a signature help pop-up or not.
///
/// Default: false
pub auto_signature_help: Option<bool>,
/// Whether to show the signature help pop-up after completions or bracket pairs inserted.
///
/// Default: true
pub show_signature_help_after_edits: Option<bool>,
/// Jupyter REPL settings.
pub jupyter: Option<JupyterContent>,
}
// Toolbar related settings
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct ToolbarContent {
/// Whether to display breadcrumbs in the editor toolbar.
///
/// Default: true
pub breadcrumbs: Option<bool>,
/// Whether to display quick action buttons in the editor toolbar.
///
/// Default: true
pub quick_actions: Option<bool>,
/// Whether to show the selections menu in the editor toolbar
///
/// Default: true
pub selections_menu: Option<bool>,
}
/// Scrollbar related settings
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct ScrollbarContent {
/// When to show the scrollbar in the editor.
///
/// Default: auto
pub show: Option<ShowScrollbar>,
/// Whether to show git diff indicators in the scrollbar.
///
/// Default: true
pub git_diff: Option<bool>,
/// Whether to show buffer search result indicators in the scrollbar.
///
/// Default: true
pub search_results: Option<bool>,
/// Whether to show selected symbol occurrences in the scrollbar.
///
/// Default: true
pub selected_symbol: Option<bool>,
/// Whether to show diagnostic indicators in the scrollbar.
///
/// Default: true
pub diagnostics: Option<bool>,
/// Whether to show cursor positions in the scrollbar.
///
/// Default: true
pub cursors: Option<bool>,
}
/// Gutter related settings
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct GutterContent {
/// Whether to show line numbers in the gutter.
///
/// Default: true
pub line_numbers: Option<bool>,
/// Whether to show code action buttons in the gutter.
///
/// Default: true
pub code_actions: Option<bool>,
/// Whether to show runnable buttons in the gutter.
///
/// Default: true
pub runnables: Option<bool>,
/// Whether to show fold buttons in the gutter.
///
/// Default: true
pub folds: Option<bool>,
}
impl EditorSettings {
pub fn jupyter_enabled(cx: &AppContext) -> bool {
EditorSettings::get_global(cx).jupyter.enabled
@@ -292,7 +362,7 @@ impl EditorSettings {
impl Settings for EditorSettings {
const KEY: Option<&'static str> = None;
type FileContent = Self;
type FileContent = EditorSettingsContent;
fn load(
sources: SettingsSources<Self::FileContent>,
+18 -4
View File
@@ -1,7 +1,7 @@
use std::sync::Arc;
use gpui::{AppContext, FontFeatures, FontWeight};
use project::project_settings::ProjectSettings;
use project::project_settings::{InlineBlameSettings, ProjectSettings};
use settings::{EditableSettingControl, Settings};
use theme::{FontFamilyCache, ThemeSettings};
use ui::{
@@ -296,7 +296,14 @@ impl EditableSettingControl for InlineGitBlameControl {
value: Self::Value,
_cx: &AppContext,
) {
settings.git.inline_blame.enabled = value;
if let Some(inline_blame) = settings.git.inline_blame.as_mut() {
inline_blame.enabled = value;
} else {
settings.git.inline_blame = Some(InlineBlameSettings {
enabled: false,
..Default::default()
});
}
}
}
@@ -342,7 +349,14 @@ impl EditableSettingControl for LineNumbersControl {
value: Self::Value,
_cx: &AppContext,
) {
settings.gutter.line_numbers = value;
if let Some(gutter) = settings.gutter.as_mut() {
gutter.line_numbers = Some(value);
} else {
settings.gutter = Some(crate::editor_settings::GutterContent {
line_numbers: Some(value),
..Default::default()
});
}
}
}
@@ -388,7 +402,7 @@ impl EditableSettingControl for RelativeLineNumbersControl {
value: Self::Value,
_cx: &AppContext,
) {
settings.relative_line_numbers = value;
settings.relative_line_numbers = Some(value);
}
}
+9 -9
View File
@@ -6964,7 +6964,7 @@ async fn test_handle_input_for_show_signature_help_auto_signature_help_true(
cx.update(|cx| {
cx.update_global::<SettingsStore, _>(|settings, cx| {
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.auto_signature_help = true;
settings.auto_signature_help = Some(true);
});
});
});
@@ -7105,8 +7105,8 @@ async fn test_handle_input_with_different_show_signature_settings(cx: &mut gpui:
cx.update(|cx| {
cx.update_global::<SettingsStore, _>(|settings, cx| {
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.auto_signature_help = false;
settings.show_signature_help_after_edits = false;
settings.auto_signature_help = Some(false);
settings.show_signature_help_after_edits = Some(false);
});
});
});
@@ -7232,8 +7232,8 @@ async fn test_handle_input_with_different_show_signature_settings(cx: &mut gpui:
cx.update(|cx| {
cx.update_global::<SettingsStore, _>(|settings, cx| {
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.auto_signature_help = false;
settings.show_signature_help_after_edits = true;
settings.auto_signature_help = Some(false);
settings.show_signature_help_after_edits = Some(true);
});
});
});
@@ -7274,8 +7274,8 @@ async fn test_handle_input_with_different_show_signature_settings(cx: &mut gpui:
cx.update(|cx| {
cx.update_global::<SettingsStore, _>(|settings, cx| {
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.auto_signature_help = true;
settings.show_signature_help_after_edits = false;
settings.auto_signature_help = Some(true);
settings.show_signature_help_after_edits = Some(false);
});
});
});
@@ -7318,7 +7318,7 @@ async fn test_signature_help(cx: &mut gpui::TestAppContext) {
cx.update(|cx| {
cx.update_global::<SettingsStore, _>(|settings, cx| {
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.auto_signature_help = true;
settings.auto_signature_help = Some(true);
});
});
});
@@ -7759,7 +7759,7 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
cx.update(|cx| {
cx.update_global::<SettingsStore, _>(|settings, cx| {
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.show_completions_on_input = false;
settings.show_completions_on_input = Some(false);
});
})
});
+11 -6
View File
@@ -1283,7 +1283,10 @@ impl EditorElement {
.row,
);
let git_gutter_setting = ProjectSettings::get_global(cx).git.git_gutter;
let git_gutter_setting = ProjectSettings::get_global(cx)
.git
.git_gutter
.unwrap_or_default();
let display_hunks = buffer_snapshot
.git_diff_hunks_in_range(buffer_start_row..buffer_end_row)
.map(|hunk| diff_hunk_to_display(&hunk, snapshot))
@@ -1363,10 +1366,12 @@ impl EditorElement {
};
let padded_line_end = line_end + em_width * INLINE_BLAME_PADDING_EM_WIDTHS;
let min_column_in_pixels = self.column_pixels(
ProjectSettings::get_global(cx).git.inline_blame.min_column as usize,
cx,
);
let min_column_in_pixels = ProjectSettings::get_global(cx)
.git
.inline_blame
.and_then(|settings| settings.min_column)
.map(|col| self.column_pixels(col as usize, cx))
.unwrap_or(px(0.));
let min_start = content_origin.x - scroll_pixel_position.x + min_column_in_pixels;
cmp::max(padded_line_end, min_start)
@@ -3326,7 +3331,7 @@ impl EditorElement {
.unwrap_or_else(|| {
matches!(
ProjectSettings::get_global(cx).git.git_gutter,
GitGutterSetting::TrackedFiles
Some(GitGutterSetting::TrackedFiles)
)
});
if show_git_gutter {