editor_settings.rs

  1use schemars::JsonSchema;
  2use serde::{Deserialize, Serialize};
  3use settings::Settings;
  4
  5#[derive(Deserialize, Clone)]
  6pub struct EditorSettings {
  7    pub cursor_blink: bool,
  8    pub hover_popover_enabled: bool,
  9    pub show_completions_on_input: bool,
 10    pub show_completion_documentation: bool,
 11    pub completion_documentation_secondary_query_debounce: u64,
 12    pub use_on_type_format: bool,
 13    pub toolbar: Toolbar,
 14    pub scrollbar: Scrollbar,
 15    pub gutter: Gutter,
 16    pub vertical_scroll_margin: f32,
 17    pub relative_line_numbers: bool,
 18    pub seed_search_query_from_cursor: SeedQuerySetting,
 19    pub multi_cursor_modifier: MultiCursorModifier,
 20    pub redact_private_values: bool,
 21    #[serde(default)]
 22    pub double_click_in_multibuffer: DoubleClickInMultibuffer,
 23}
 24
 25/// When to populate a new search's query based on the text under the cursor.
 26#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 27#[serde(rename_all = "snake_case")]
 28pub enum SeedQuerySetting {
 29    /// Always populate the search query with the word under the cursor.
 30    Always,
 31    /// Only populate the search query when there is text selected.
 32    Selection,
 33    /// Never populate the search query
 34    Never,
 35}
 36
 37/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
 38#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 39#[serde(rename_all = "snake_case")]
 40pub enum DoubleClickInMultibuffer {
 41    /// Behave as a regular buffer and select the whole word.
 42    #[default]
 43    Select,
 44    /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
 45    /// Otherwise, behave as a regular buffer and select the whole word.
 46    Open,
 47}
 48
 49#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 50pub struct Toolbar {
 51    pub breadcrumbs: bool,
 52    pub quick_actions: bool,
 53}
 54
 55#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 56pub struct Scrollbar {
 57    pub show: ShowScrollbar,
 58    pub git_diff: bool,
 59    pub selections: bool,
 60    pub symbols_selections: bool,
 61    pub diagnostics: bool,
 62}
 63
 64#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 65pub struct Gutter {
 66    pub line_numbers: bool,
 67    pub code_actions: bool,
 68    pub folds: bool,
 69}
 70
 71/// When to show the scrollbar in the editor.
 72///
 73/// Default: auto
 74#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 75#[serde(rename_all = "snake_case")]
 76pub enum ShowScrollbar {
 77    /// Show the scrollbar if there's important information or
 78    /// follow the system's configured behavior.
 79    Auto,
 80    /// Match the system's configured behavior.
 81    System,
 82    /// Always show the scrollbar.
 83    Always,
 84    /// Never show the scrollbar.
 85    Never,
 86}
 87
 88/// The key to use for adding multiple cursors
 89///
 90/// Default: alt
 91#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 92#[serde(rename_all = "snake_case")]
 93pub enum MultiCursorModifier {
 94    Alt,
 95    #[serde(alias = "cmd", alias = "ctrl")]
 96    CmdOrCtrl,
 97}
 98
 99#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
100pub struct EditorSettingsContent {
101    /// Whether the cursor blinks in the editor.
102    ///
103    /// Default: true
104    pub cursor_blink: Option<bool>,
105    /// Whether to show the informational hover box when moving the mouse
106    /// over symbols in the editor.
107    ///
108    /// Default: true
109    pub hover_popover_enabled: Option<bool>,
110    /// Whether to pop the completions menu while typing in an editor without
111    /// explicitly requesting it.
112    ///
113    /// Default: true
114    pub show_completions_on_input: Option<bool>,
115    /// Whether to display inline and alongside documentation for items in the
116    /// completions menu.
117    ///
118    /// Default: true
119    pub show_completion_documentation: Option<bool>,
120    /// The debounce delay before re-querying the language server for completion
121    /// documentation when not included in original completion list.
122    ///
123    /// Default: 300 ms
124    pub completion_documentation_secondary_query_debounce: Option<u64>,
125    /// Whether to use additional LSP queries to format (and amend) the code after
126    /// every "trigger" symbol input, defined by LSP server capabilities.
127    ///
128    /// Default: true
129    pub use_on_type_format: Option<bool>,
130    /// Toolbar related settings
131    pub toolbar: Option<ToolbarContent>,
132    /// Scrollbar related settings
133    pub scrollbar: Option<ScrollbarContent>,
134    /// Gutter related settings
135    pub gutter: Option<GutterContent>,
136    /// The number of lines to keep above/below the cursor when auto-scrolling.
137    ///
138    /// Default: 3.
139    pub vertical_scroll_margin: Option<f32>,
140    /// Whether the line numbers on editors gutter are relative or not.
141    ///
142    /// Default: false
143    pub relative_line_numbers: Option<bool>,
144    /// When to populate a new search's query based on the text under the cursor.
145    ///
146    /// Default: always
147    pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
148    /// The key to use for adding multiple cursors
149    ///
150    /// Default: alt
151    pub multi_cursor_modifier: Option<MultiCursorModifier>,
152    /// Hide the values of variables in `private` files, as defined by the
153    /// private_files setting. This only changes the visual representation,
154    /// the values are still present in the file and can be selected / copied / pasted
155    ///
156    /// Default: false
157    pub redact_private_values: Option<bool>,
158
159    /// What to do when multibuffer is double clicked in some of its excerpts
160    /// (parts of singleton buffers).
161    ///
162    /// Default: select
163    pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
164}
165
166// Toolbar related settings
167#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
168pub struct ToolbarContent {
169    /// Whether to display breadcrumbs in the editor toolbar.
170    ///
171    /// Default: true
172    pub breadcrumbs: Option<bool>,
173    /// Whether to display quik action buttons in the editor toolbar.
174    ///
175    /// Default: true
176    pub quick_actions: Option<bool>,
177}
178
179/// Scrollbar related settings
180#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
181pub struct ScrollbarContent {
182    /// When to show the scrollbar in the editor.
183    ///
184    /// Default: auto
185    pub show: Option<ShowScrollbar>,
186    /// Whether to show git diff indicators in the scrollbar.
187    ///
188    /// Default: true
189    pub git_diff: Option<bool>,
190    /// Whether to show buffer search result markers in the scrollbar.
191    ///
192    /// Default: true
193    pub selections: Option<bool>,
194    /// Whether to show symbols highlighted markers in the scrollbar.
195    ///
196    /// Default: true
197    pub symbols_selections: Option<bool>,
198    /// Whether to show diagnostic indicators in the scrollbar.
199    ///
200    /// Default: true
201    pub diagnostics: Option<bool>,
202}
203
204/// Gutter related settings
205#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
206pub struct GutterContent {
207    /// Whether to show line numbers in the gutter.
208    ///
209    /// Default: true
210    pub line_numbers: Option<bool>,
211    /// Whether to show code action buttons in the gutter.
212    ///
213    /// Default: true
214    pub code_actions: Option<bool>,
215    /// Whether to show fold buttons in the gutter.
216    ///
217    /// Default: true
218    pub folds: Option<bool>,
219}
220
221impl Settings for EditorSettings {
222    const KEY: Option<&'static str> = None;
223
224    type FileContent = EditorSettingsContent;
225
226    fn load(
227        default_value: &Self::FileContent,
228        user_values: &[&Self::FileContent],
229        _: &mut gpui::AppContext,
230    ) -> anyhow::Result<Self> {
231        Self::load_via_json_merge(default_value, user_values)
232    }
233}