editor_settings.rs

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