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