editor_settings.rs

  1use gpui::App;
  2use language::CursorShape;
  3use schemars::JsonSchema;
  4use serde::{Deserialize, Serialize};
  5use settings::{Settings, SettingsSources};
  6
  7#[derive(Deserialize, Clone)]
  8pub struct EditorSettings {
  9    pub cursor_blink: bool,
 10    pub cursor_shape: Option<CursorShape>,
 11    pub current_line_highlight: CurrentLineHighlight,
 12    pub selection_highlight: bool,
 13    pub selection_highlight_debounce: u64,
 14    pub lsp_highlight_debounce: u64,
 15    pub hover_popover_enabled: bool,
 16    pub hover_popover_delay: u64,
 17    pub toolbar: Toolbar,
 18    pub scrollbar: Scrollbar,
 19    pub gutter: Gutter,
 20    pub scroll_beyond_last_line: ScrollBeyondLastLine,
 21    pub vertical_scroll_margin: f32,
 22    pub autoscroll_on_clicks: bool,
 23    pub horizontal_scroll_margin: f32,
 24    pub scroll_sensitivity: f32,
 25    pub relative_line_numbers: bool,
 26    pub seed_search_query_from_cursor: SeedQuerySetting,
 27    pub use_smartcase_search: bool,
 28    pub multi_cursor_modifier: MultiCursorModifier,
 29    pub redact_private_values: bool,
 30    pub expand_excerpt_lines: u32,
 31    pub middle_click_paste: bool,
 32    #[serde(default)]
 33    pub double_click_in_multibuffer: DoubleClickInMultibuffer,
 34    pub search_wrap: bool,
 35    #[serde(default)]
 36    pub search: SearchSettings,
 37    pub auto_signature_help: bool,
 38    pub show_signature_help_after_edits: bool,
 39    pub jupyter: Jupyter,
 40}
 41
 42#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 43#[serde(rename_all = "snake_case")]
 44pub enum CurrentLineHighlight {
 45    // Don't highlight the current line.
 46    None,
 47    // Highlight the gutter area.
 48    Gutter,
 49    // Highlight the editor area.
 50    Line,
 51    // Highlight the full line.
 52    All,
 53}
 54
 55/// When to populate a new search's query based on the text under the cursor.
 56#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 57#[serde(rename_all = "snake_case")]
 58pub enum SeedQuerySetting {
 59    /// Always populate the search query with the word under the cursor.
 60    Always,
 61    /// Only populate the search query when there is text selected.
 62    Selection,
 63    /// Never populate the search query
 64    Never,
 65}
 66
 67/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
 68#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 69#[serde(rename_all = "snake_case")]
 70pub enum DoubleClickInMultibuffer {
 71    /// Behave as a regular buffer and select the whole word.
 72    #[default]
 73    Select,
 74    /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
 75    /// Otherwise, behave as a regular buffer and select the whole word.
 76    Open,
 77}
 78
 79#[derive(Debug, Clone, Deserialize)]
 80pub struct Jupyter {
 81    /// Whether the Jupyter feature is enabled.
 82    ///
 83    /// Default: true
 84    pub enabled: bool,
 85}
 86
 87#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 88#[serde(rename_all = "snake_case")]
 89pub struct JupyterContent {
 90    /// Whether the Jupyter feature is enabled.
 91    ///
 92    /// Default: true
 93    pub enabled: Option<bool>,
 94}
 95
 96#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 97pub struct Toolbar {
 98    pub breadcrumbs: bool,
 99    pub quick_actions: bool,
100    pub selections_menu: bool,
101}
102
103#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
104pub struct Scrollbar {
105    pub show: ShowScrollbar,
106    pub git_diff: bool,
107    pub selected_text: bool,
108    pub selected_symbol: bool,
109    pub search_results: bool,
110    pub diagnostics: ScrollbarDiagnostics,
111    pub cursors: bool,
112    pub axes: ScrollbarAxes,
113}
114
115#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
116pub struct Gutter {
117    pub line_numbers: bool,
118    pub code_actions: bool,
119    pub runnables: bool,
120    pub breakpoints: bool,
121    pub folds: bool,
122}
123
124/// When to show the scrollbar in the editor.
125///
126/// Default: auto
127#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
128#[serde(rename_all = "snake_case")]
129pub enum ShowScrollbar {
130    /// Show the scrollbar if there's important information or
131    /// follow the system's configured behavior.
132    Auto,
133    /// Match the system's configured behavior.
134    System,
135    /// Always show the scrollbar.
136    Always,
137    /// Never show the scrollbar.
138    Never,
139}
140
141/// Forcefully enable or disable the scrollbar for each axis
142#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
143#[serde(rename_all = "lowercase")]
144pub struct ScrollbarAxes {
145    /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
146    ///
147    /// Default: true
148    pub horizontal: bool,
149
150    /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
151    ///
152    /// Default: true
153    pub vertical: bool,
154}
155
156/// Which diagnostic indicators to show in the scrollbar.
157///
158/// Default: all
159#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
160#[serde(rename_all = "lowercase")]
161pub enum ScrollbarDiagnostics {
162    /// Show all diagnostic levels: hint, information, warnings, error.
163    All,
164    /// Show only the following diagnostic levels: information, warning, error.
165    Information,
166    /// Show only the following diagnostic levels: warning, error.
167    Warning,
168    /// Show only the following diagnostic level: error.
169    Error,
170    /// Do not show diagnostics.
171    None,
172}
173
174/// The key to use for adding multiple cursors
175///
176/// Default: alt
177#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
178#[serde(rename_all = "snake_case")]
179pub enum MultiCursorModifier {
180    Alt,
181    #[serde(alias = "cmd", alias = "ctrl")]
182    CmdOrCtrl,
183}
184
185/// Whether the editor will scroll beyond the last line.
186///
187/// Default: one_page
188#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
189#[serde(rename_all = "snake_case")]
190pub enum ScrollBeyondLastLine {
191    /// The editor will not scroll beyond the last line.
192    Off,
193
194    /// The editor will scroll beyond the last line by one page.
195    OnePage,
196
197    /// The editor will scroll beyond the last line by the same number of lines as vertical_scroll_margin.
198    VerticalScrollMargin,
199}
200
201/// Default options for buffer and project search items.
202#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
203pub struct SearchSettings {
204    #[serde(default)]
205    pub whole_word: bool,
206    #[serde(default)]
207    pub case_sensitive: bool,
208    #[serde(default)]
209    pub include_ignored: bool,
210    #[serde(default)]
211    pub regex: bool,
212}
213
214#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
215pub struct EditorSettingsContent {
216    /// Whether the cursor blinks in the editor.
217    ///
218    /// Default: true
219    pub cursor_blink: Option<bool>,
220    /// Cursor shape for the default editor.
221    /// Can be "bar", "block", "underline", or "hollow".
222    ///
223    /// Default: None
224    pub cursor_shape: Option<CursorShape>,
225    /// How to highlight the current line in the editor.
226    ///
227    /// Default: all
228    pub current_line_highlight: Option<CurrentLineHighlight>,
229    /// Whether to highlight all occurrences of the selected text in an editor.
230    ///
231    /// Default: true
232    pub selection_highlight: Option<bool>,
233    /// The debounce delay before querying highlights based on the selected text.
234    ///
235    /// Default: 75
236    pub selection_highlight_debounce: Option<u64>,
237    /// The debounce delay before querying highlights from the language
238    /// server based on the current cursor location.
239    ///
240    /// Default: 75
241    pub lsp_highlight_debounce: Option<u64>,
242    /// Whether to show the informational hover box when moving the mouse
243    /// over symbols in the editor.
244    ///
245    /// Default: true
246    pub hover_popover_enabled: Option<bool>,
247    /// Time to wait before showing the informational hover box
248    ///
249    /// Default: 350
250    pub hover_popover_delay: Option<u64>,
251    /// Toolbar related settings
252    pub toolbar: Option<ToolbarContent>,
253    /// Scrollbar related settings
254    pub scrollbar: Option<ScrollbarContent>,
255    /// Gutter related settings
256    pub gutter: Option<GutterContent>,
257    /// Whether the editor will scroll beyond the last line.
258    ///
259    /// Default: one_page
260    pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
261    /// The number of lines to keep above/below the cursor when auto-scrolling.
262    ///
263    /// Default: 3.
264    pub vertical_scroll_margin: Option<f32>,
265    /// Whether to scroll when clicking near the edge of the visible text area.
266    ///
267    /// Default: false
268    pub autoscroll_on_clicks: Option<bool>,
269    /// The number of characters to keep on either side when scrolling with the mouse.
270    ///
271    /// Default: 5.
272    pub horizontal_scroll_margin: Option<f32>,
273    /// Scroll sensitivity multiplier. This multiplier is applied
274    /// to both the horizontal and vertical delta values while scrolling.
275    ///
276    /// Default: 1.0
277    pub scroll_sensitivity: Option<f32>,
278    /// Whether the line numbers on editors gutter are relative or not.
279    ///
280    /// Default: false
281    pub relative_line_numbers: Option<bool>,
282    /// When to populate a new search's query based on the text under the cursor.
283    ///
284    /// Default: always
285    pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
286    pub use_smartcase_search: Option<bool>,
287    /// The key to use for adding multiple cursors
288    ///
289    /// Default: alt
290    pub multi_cursor_modifier: Option<MultiCursorModifier>,
291    /// Hide the values of variables in `private` files, as defined by the
292    /// private_files setting. This only changes the visual representation,
293    /// the values are still present in the file and can be selected / copied / pasted
294    ///
295    /// Default: false
296    pub redact_private_values: Option<bool>,
297
298    /// How many lines to expand the multibuffer excerpts by default
299    ///
300    /// Default: 3
301    pub expand_excerpt_lines: Option<u32>,
302
303    /// Whether to enable middle-click paste on Linux
304    ///
305    /// Default: true
306    pub middle_click_paste: Option<bool>,
307
308    /// What to do when multibuffer is double clicked in some of its excerpts
309    /// (parts of singleton buffers).
310    ///
311    /// Default: select
312    pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
313    /// Whether the editor search results will loop
314    ///
315    /// Default: true
316    pub search_wrap: Option<bool>,
317
318    /// Defaults to use when opening a new buffer and project search items.
319    ///
320    /// Default: nothing is enabled
321    pub search: Option<SearchSettings>,
322
323    /// Whether to automatically show a signature help pop-up or not.
324    ///
325    /// Default: false
326    pub auto_signature_help: Option<bool>,
327
328    /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
329    ///
330    /// Default: false
331    pub show_signature_help_after_edits: Option<bool>,
332
333    /// Jupyter REPL settings.
334    pub jupyter: Option<JupyterContent>,
335}
336
337// Toolbar related settings
338#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
339pub struct ToolbarContent {
340    /// Whether to display breadcrumbs in the editor toolbar.
341    ///
342    /// Default: true
343    pub breadcrumbs: Option<bool>,
344    /// Whether to display quick action buttons in the editor toolbar.
345    ///
346    /// Default: true
347    pub quick_actions: Option<bool>,
348
349    /// Whether to show the selections menu in the editor toolbar
350    ///
351    /// Default: true
352    pub selections_menu: Option<bool>,
353}
354
355/// Scrollbar related settings
356#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
357pub struct ScrollbarContent {
358    /// When to show the scrollbar in the editor.
359    ///
360    /// Default: auto
361    pub show: Option<ShowScrollbar>,
362    /// Whether to show git diff indicators in the scrollbar.
363    ///
364    /// Default: true
365    pub git_diff: Option<bool>,
366    /// Whether to show buffer search result indicators in the scrollbar.
367    ///
368    /// Default: true
369    pub search_results: Option<bool>,
370    /// Whether to show selected text occurrences in the scrollbar.
371    ///
372    /// Default: true
373    pub selected_text: Option<bool>,
374    /// Whether to show selected symbol occurrences in the scrollbar.
375    ///
376    /// Default: true
377    pub selected_symbol: Option<bool>,
378    /// Which diagnostic indicators to show in the scrollbar:
379    ///
380    /// Default: all
381    pub diagnostics: Option<ScrollbarDiagnostics>,
382    /// Whether to show cursor positions in the scrollbar.
383    ///
384    /// Default: true
385    pub cursors: Option<bool>,
386    /// Forcefully enable or disable the scrollbar for each axis
387    pub axes: Option<ScrollbarAxesContent>,
388}
389
390/// Forcefully enable or disable the scrollbar for each axis
391#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
392pub struct ScrollbarAxesContent {
393    /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
394    ///
395    /// Default: true
396    horizontal: Option<bool>,
397
398    /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
399    ///
400    /// Default: true
401    vertical: Option<bool>,
402}
403
404/// Gutter related settings
405#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
406pub struct GutterContent {
407    /// Whether to show line numbers in the gutter.
408    ///
409    /// Default: true
410    pub line_numbers: Option<bool>,
411    /// Whether to show code action buttons in the gutter.
412    ///
413    /// Default: true
414    pub code_actions: Option<bool>,
415    /// Whether to show runnable buttons in the gutter.
416    ///
417    /// Default: true
418    pub runnables: Option<bool>,
419    /// Whether to show breakpoints in the gutter.
420    ///
421    /// Default: true
422    pub breakpoints: Option<bool>,
423    /// Whether to show fold buttons in the gutter.
424    ///
425    /// Default: true
426    pub folds: Option<bool>,
427}
428
429impl EditorSettings {
430    pub fn jupyter_enabled(cx: &App) -> bool {
431        EditorSettings::get_global(cx).jupyter.enabled
432    }
433}
434
435impl Settings for EditorSettings {
436    const KEY: Option<&'static str> = None;
437
438    type FileContent = EditorSettingsContent;
439
440    fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> anyhow::Result<Self> {
441        sources.json_merge()
442    }
443}