editor_settings.rs

  1use core::num;
  2use std::num::NonZeroU32;
  3
  4use gpui::App;
  5use language::CursorShape;
  6use project::project_settings::DiagnosticSeverity;
  7use schemars::JsonSchema;
  8use serde::{Deserialize, Serialize};
  9use settings::{Settings, SettingsSources, VsCodeSettings};
 10use util::serde::default_true;
 11
 12/// Imports from the VSCode settings at
 13/// https://code.visualstudio.com/docs/reference/default-settings
 14#[derive(Deserialize, Clone)]
 15pub struct EditorSettings {
 16    pub cursor_blink: bool,
 17    pub cursor_shape: Option<CursorShape>,
 18    pub current_line_highlight: CurrentLineHighlight,
 19    pub selection_highlight: bool,
 20    pub lsp_highlight_debounce: u64,
 21    pub hover_popover_enabled: bool,
 22    pub hover_popover_delay: u64,
 23    pub toolbar: Toolbar,
 24    pub scrollbar: Scrollbar,
 25    pub minimap: Minimap,
 26    pub gutter: Gutter,
 27    pub scroll_beyond_last_line: ScrollBeyondLastLine,
 28    pub vertical_scroll_margin: f32,
 29    pub autoscroll_on_clicks: bool,
 30    pub horizontal_scroll_margin: f32,
 31    pub scroll_sensitivity: f32,
 32    pub fast_scroll_sensitivity: f32,
 33    pub relative_line_numbers: bool,
 34    pub seed_search_query_from_cursor: SeedQuerySetting,
 35    pub use_smartcase_search: bool,
 36    pub multi_cursor_modifier: MultiCursorModifier,
 37    pub redact_private_values: bool,
 38    pub expand_excerpt_lines: u32,
 39    pub middle_click_paste: bool,
 40    #[serde(default)]
 41    pub double_click_in_multibuffer: DoubleClickInMultibuffer,
 42    pub search_wrap: bool,
 43    #[serde(default)]
 44    pub search: SearchSettings,
 45    pub auto_signature_help: bool,
 46    pub show_signature_help_after_edits: bool,
 47    #[serde(default)]
 48    pub go_to_definition_fallback: GoToDefinitionFallback,
 49    pub jupyter: Jupyter,
 50    pub hide_mouse: Option<HideMouseMode>,
 51    pub snippet_sort_order: SnippetSortOrder,
 52    #[serde(default)]
 53    pub diagnostics_max_severity: Option<DiagnosticSeverity>,
 54    pub inline_code_actions: bool,
 55    pub drag_and_drop_selection: DragAndDropSelection,
 56    pub lsp_document_colors: DocumentColorsRenderMode,
 57}
 58
 59/// How to render LSP `textDocument/documentColor` colors in the editor.
 60#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 61#[serde(rename_all = "snake_case")]
 62pub enum DocumentColorsRenderMode {
 63    /// Do not query and render document colors.
 64    None,
 65    /// Render document colors as inlay hints near the color text.
 66    #[default]
 67    Inlay,
 68    /// Draw a border around the color text.
 69    Border,
 70    /// Draw a background behind the color text.
 71    Background,
 72}
 73
 74#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 75#[serde(rename_all = "snake_case")]
 76pub enum CurrentLineHighlight {
 77    // Don't highlight the current line.
 78    None,
 79    // Highlight the gutter area.
 80    Gutter,
 81    // Highlight the editor area.
 82    Line,
 83    // Highlight the full line.
 84    All,
 85}
 86
 87/// When to populate a new search's query based on the text under the cursor.
 88#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 89#[serde(rename_all = "snake_case")]
 90pub enum SeedQuerySetting {
 91    /// Always populate the search query with the word under the cursor.
 92    Always,
 93    /// Only populate the search query when there is text selected.
 94    Selection,
 95    /// Never populate the search query
 96    Never,
 97}
 98
 99/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
100#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
101#[serde(rename_all = "snake_case")]
102pub enum DoubleClickInMultibuffer {
103    /// Behave as a regular buffer and select the whole word.
104    #[default]
105    Select,
106    /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
107    /// Otherwise, behave as a regular buffer and select the whole word.
108    Open,
109}
110
111#[derive(Debug, Clone, Deserialize)]
112pub struct Jupyter {
113    /// Whether the Jupyter feature is enabled.
114    ///
115    /// Default: true
116    pub enabled: bool,
117}
118
119#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
120#[serde(rename_all = "snake_case")]
121pub struct JupyterContent {
122    /// Whether the Jupyter feature is enabled.
123    ///
124    /// Default: true
125    pub enabled: Option<bool>,
126}
127
128#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
129pub struct Toolbar {
130    pub breadcrumbs: bool,
131    pub quick_actions: bool,
132    pub selections_menu: bool,
133    pub agent_review: bool,
134    pub code_actions: bool,
135}
136
137#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
138pub struct Scrollbar {
139    pub show: ShowScrollbar,
140    pub git_diff: bool,
141    pub selected_text: bool,
142    pub selected_symbol: bool,
143    pub search_results: bool,
144    pub diagnostics: ScrollbarDiagnostics,
145    pub cursors: bool,
146    pub axes: ScrollbarAxes,
147}
148
149#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
150pub struct Minimap {
151    pub show: ShowMinimap,
152    pub display_in: DisplayIn,
153    pub thumb: MinimapThumb,
154    pub thumb_border: MinimapThumbBorder,
155    pub current_line_highlight: Option<CurrentLineHighlight>,
156    pub max_width_columns: num::NonZeroU32,
157}
158
159impl Minimap {
160    pub fn minimap_enabled(&self) -> bool {
161        self.show != ShowMinimap::Never
162    }
163
164    #[inline]
165    pub fn on_active_editor(&self) -> bool {
166        self.display_in == DisplayIn::ActiveEditor
167    }
168
169    pub fn with_show_override(self) -> Self {
170        Self {
171            show: ShowMinimap::Always,
172            ..self
173        }
174    }
175}
176
177#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
178pub struct Gutter {
179    pub min_line_number_digits: usize,
180    pub line_numbers: bool,
181    pub runnables: bool,
182    pub breakpoints: bool,
183    pub folds: bool,
184}
185
186/// When to show the scrollbar in the editor.
187///
188/// Default: auto
189#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
190#[serde(rename_all = "snake_case")]
191pub enum ShowScrollbar {
192    /// Show the scrollbar if there's important information or
193    /// follow the system's configured behavior.
194    Auto,
195    /// Match the system's configured behavior.
196    System,
197    /// Always show the scrollbar.
198    Always,
199    /// Never show the scrollbar.
200    Never,
201}
202
203/// When to show the minimap in the editor.
204///
205/// Default: never
206#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
207#[serde(rename_all = "snake_case")]
208pub enum ShowMinimap {
209    /// Follow the visibility of the scrollbar.
210    Auto,
211    /// Always show the minimap.
212    Always,
213    /// Never show the minimap.
214    #[default]
215    Never,
216}
217
218/// Where to show the minimap in the editor.
219///
220/// Default: all_editors
221#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
222#[serde(rename_all = "snake_case")]
223pub enum DisplayIn {
224    /// Show on all open editors.
225    AllEditors,
226    /// Show the minimap on the active editor only.
227    #[default]
228    ActiveEditor,
229}
230
231/// When to show the minimap thumb.
232///
233/// Default: always
234#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
235#[serde(rename_all = "snake_case")]
236pub enum MinimapThumb {
237    /// Show the minimap thumb only when the mouse is hovering over the minimap.
238    Hover,
239    /// Always show the minimap thumb.
240    #[default]
241    Always,
242}
243
244/// Defines the border style for the minimap's scrollbar thumb.
245///
246/// Default: left_open
247#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
248#[serde(rename_all = "snake_case")]
249pub enum MinimapThumbBorder {
250    /// Displays a border on all sides of the thumb.
251    Full,
252    /// Displays a border on all sides except the left side of the thumb.
253    #[default]
254    LeftOpen,
255    /// Displays a border on all sides except the right side of the thumb.
256    RightOpen,
257    /// Displays a border only on the left side of the thumb.
258    LeftOnly,
259    /// Displays the thumb without any border.
260    None,
261}
262
263/// Forcefully enable or disable the scrollbar for each axis
264#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
265#[serde(rename_all = "lowercase")]
266pub struct ScrollbarAxes {
267    /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
268    ///
269    /// Default: true
270    pub horizontal: bool,
271
272    /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
273    ///
274    /// Default: true
275    pub vertical: bool,
276}
277
278/// Whether to allow drag and drop text selection in buffer.
279#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
280pub struct DragAndDropSelection {
281    /// When true, enables drag and drop text selection in buffer.
282    ///
283    /// Default: true
284    #[serde(default = "default_true")]
285    pub enabled: bool,
286
287    /// The delay in milliseconds that must elapse before drag and drop is allowed. Otherwise, a new text selection is created.
288    ///
289    /// Default: 300
290    #[serde(default = "default_drag_and_drop_selection_delay_ms")]
291    pub delay: u64,
292}
293
294fn default_drag_and_drop_selection_delay_ms() -> u64 {
295    300
296}
297
298/// Which diagnostic indicators to show in the scrollbar.
299///
300/// Default: all
301#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
302#[serde(rename_all = "lowercase")]
303pub enum ScrollbarDiagnostics {
304    /// Show all diagnostic levels: hint, information, warnings, error.
305    All,
306    /// Show only the following diagnostic levels: information, warning, error.
307    Information,
308    /// Show only the following diagnostic levels: warning, error.
309    Warning,
310    /// Show only the following diagnostic level: error.
311    Error,
312    /// Do not show diagnostics.
313    None,
314}
315
316/// The key to use for adding multiple cursors
317///
318/// Default: alt
319#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
320#[serde(rename_all = "snake_case")]
321pub enum MultiCursorModifier {
322    Alt,
323    #[serde(alias = "cmd", alias = "ctrl")]
324    CmdOrCtrl,
325}
326
327/// Whether the editor will scroll beyond the last line.
328///
329/// Default: one_page
330#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
331#[serde(rename_all = "snake_case")]
332pub enum ScrollBeyondLastLine {
333    /// The editor will not scroll beyond the last line.
334    Off,
335
336    /// The editor will scroll beyond the last line by one page.
337    OnePage,
338
339    /// The editor will scroll beyond the last line by the same number of lines as vertical_scroll_margin.
340    VerticalScrollMargin,
341}
342
343/// Default options for buffer and project search items.
344#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
345pub struct SearchSettings {
346    /// Whether to show the project search button in the status bar.
347    #[serde(default = "default_true")]
348    pub button: bool,
349    #[serde(default)]
350    pub whole_word: bool,
351    #[serde(default)]
352    pub case_sensitive: bool,
353    #[serde(default)]
354    pub include_ignored: bool,
355    #[serde(default)]
356    pub regex: bool,
357}
358
359/// What to do when go to definition yields no results.
360#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
361#[serde(rename_all = "snake_case")]
362pub enum GoToDefinitionFallback {
363    /// Disables the fallback.
364    None,
365    /// Looks up references of the same symbol instead.
366    #[default]
367    FindAllReferences,
368}
369
370/// Determines when the mouse cursor should be hidden in an editor or input box.
371///
372/// Default: on_typing_and_movement
373#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
374#[serde(rename_all = "snake_case")]
375pub enum HideMouseMode {
376    /// Never hide the mouse cursor
377    Never,
378    /// Hide only when typing
379    OnTyping,
380    /// Hide on both typing and cursor movement
381    #[default]
382    OnTypingAndMovement,
383}
384
385/// Determines how snippets are sorted relative to other completion items.
386///
387/// Default: inline
388#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
389#[serde(rename_all = "snake_case")]
390pub enum SnippetSortOrder {
391    /// Place snippets at the top of the completion list
392    Top,
393    /// Sort snippets normally using the default comparison logic
394    #[default]
395    Inline,
396    /// Place snippets at the bottom of the completion list
397    Bottom,
398    /// Do not show snippets in the completion list
399    None,
400}
401
402#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
403pub struct EditorSettingsContent {
404    /// Whether the cursor blinks in the editor.
405    ///
406    /// Default: true
407    pub cursor_blink: Option<bool>,
408    /// Cursor shape for the default editor.
409    /// Can be "bar", "block", "underline", or "hollow".
410    ///
411    /// Default: None
412    pub cursor_shape: Option<CursorShape>,
413    /// Determines when the mouse cursor should be hidden in an editor or input box.
414    ///
415    /// Default: on_typing_and_movement
416    pub hide_mouse: Option<HideMouseMode>,
417    /// Determines how snippets are sorted relative to other completion items.
418    ///
419    /// Default: inline
420    pub snippet_sort_order: Option<SnippetSortOrder>,
421    /// How to highlight the current line in the editor.
422    ///
423    /// Default: all
424    pub current_line_highlight: Option<CurrentLineHighlight>,
425    /// Whether to highlight all occurrences of the selected text in an editor.
426    ///
427    /// Default: true
428    pub selection_highlight: Option<bool>,
429    /// The debounce delay before querying highlights from the language
430    /// server based on the current cursor location.
431    ///
432    /// Default: 75
433    pub lsp_highlight_debounce: Option<u64>,
434    /// Whether to show the informational hover box when moving the mouse
435    /// over symbols in the editor.
436    ///
437    /// Default: true
438    pub hover_popover_enabled: Option<bool>,
439    /// Time to wait in milliseconds before showing the informational hover box.
440    ///
441    /// Default: 300
442    pub hover_popover_delay: Option<u64>,
443    /// Toolbar related settings
444    pub toolbar: Option<ToolbarContent>,
445    /// Scrollbar related settings
446    pub scrollbar: Option<ScrollbarContent>,
447    /// Minimap related settings
448    pub minimap: Option<MinimapContent>,
449    /// Gutter related settings
450    pub gutter: Option<GutterContent>,
451    /// Whether the editor will scroll beyond the last line.
452    ///
453    /// Default: one_page
454    pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
455    /// The number of lines to keep above/below the cursor when auto-scrolling.
456    ///
457    /// Default: 3.
458    pub vertical_scroll_margin: Option<f32>,
459    /// Whether to scroll when clicking near the edge of the visible text area.
460    ///
461    /// Default: false
462    pub autoscroll_on_clicks: Option<bool>,
463    /// The number of characters to keep on either side when scrolling with the mouse.
464    ///
465    /// Default: 5.
466    pub horizontal_scroll_margin: Option<f32>,
467    /// Scroll sensitivity multiplier. This multiplier is applied
468    /// to both the horizontal and vertical delta values while scrolling.
469    ///
470    /// Default: 1.0
471    pub scroll_sensitivity: Option<f32>,
472    /// Scroll sensitivity multiplier for fast scrolling. This multiplier is applied
473    /// to both the horizontal and vertical delta values while scrolling. Fast scrolling
474    /// happens when a user holds the alt or option key while scrolling.
475    ///
476    /// Default: 4.0
477    pub fast_scroll_sensitivity: Option<f32>,
478    /// Whether the line numbers on editors gutter are relative or not.
479    ///
480    /// Default: false
481    pub relative_line_numbers: Option<bool>,
482    /// When to populate a new search's query based on the text under the cursor.
483    ///
484    /// Default: always
485    pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
486    pub use_smartcase_search: Option<bool>,
487    /// Determines the modifier to be used to add multiple cursors with the mouse. The open hover link mouse gestures will adapt such that it do not conflict with the multicursor modifier.
488    ///
489    /// Default: alt
490    pub multi_cursor_modifier: Option<MultiCursorModifier>,
491    /// Hide the values of variables in `private` files, as defined by the
492    /// private_files setting. This only changes the visual representation,
493    /// the values are still present in the file and can be selected / copied / pasted
494    ///
495    /// Default: false
496    pub redact_private_values: Option<bool>,
497
498    /// How many lines to expand the multibuffer excerpts by default
499    ///
500    /// Default: 3
501    pub expand_excerpt_lines: Option<u32>,
502
503    /// Whether to enable middle-click paste on Linux
504    ///
505    /// Default: true
506    pub middle_click_paste: Option<bool>,
507
508    /// What to do when multibuffer is double clicked in some of its excerpts
509    /// (parts of singleton buffers).
510    ///
511    /// Default: select
512    pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
513    /// Whether the editor search results will loop
514    ///
515    /// Default: true
516    pub search_wrap: Option<bool>,
517
518    /// Defaults to use when opening a new buffer and project search items.
519    ///
520    /// Default: nothing is enabled
521    pub search: Option<SearchSettings>,
522
523    /// Whether to automatically show a signature help pop-up or not.
524    ///
525    /// Default: false
526    pub auto_signature_help: Option<bool>,
527
528    /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
529    ///
530    /// Default: false
531    pub show_signature_help_after_edits: Option<bool>,
532
533    /// Whether to follow-up empty go to definition responses from the language server or not.
534    /// `FindAllReferences` allows to look up references of the same symbol instead.
535    /// `None` disables the fallback.
536    ///
537    /// Default: FindAllReferences
538    pub go_to_definition_fallback: Option<GoToDefinitionFallback>,
539
540    /// Jupyter REPL settings.
541    pub jupyter: Option<JupyterContent>,
542
543    /// Which level to use to filter out diagnostics displayed in the editor.
544    ///
545    /// Affects the editor rendering only, and does not interrupt
546    /// the functionality of diagnostics fetching and project diagnostics editor.
547    /// Which files containing diagnostic errors/warnings to mark in the tabs.
548    /// Diagnostics are only shown when file icons are also active.
549    ///
550    /// Shows all diagnostics if not specified.
551    ///
552    /// Default: warning
553    #[serde(default)]
554    pub diagnostics_max_severity: Option<DiagnosticSeverity>,
555
556    /// Whether to show code action button at start of buffer line.
557    ///
558    /// Default: true
559    pub inline_code_actions: Option<bool>,
560
561    /// Drag and drop related settings
562    pub drag_and_drop_selection: Option<DragAndDropSelection>,
563
564    /// How to render LSP `textDocument/documentColor` colors in the editor.
565    ///
566    /// Default: [`DocumentColorsRenderMode::Inlay`]
567    pub lsp_document_colors: Option<DocumentColorsRenderMode>,
568}
569
570// Toolbar related settings
571#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
572pub struct ToolbarContent {
573    /// Whether to display breadcrumbs in the editor toolbar.
574    ///
575    /// Default: true
576    pub breadcrumbs: Option<bool>,
577    /// Whether to display quick action buttons in the editor toolbar.
578    ///
579    /// Default: true
580    pub quick_actions: Option<bool>,
581    /// Whether to show the selections menu in the editor toolbar.
582    ///
583    /// Default: true
584    pub selections_menu: Option<bool>,
585    /// Whether to display Agent review buttons in the editor toolbar.
586    /// Only applicable while reviewing a file edited by the Agent.
587    ///
588    /// Default: true
589    pub agent_review: Option<bool>,
590    /// Whether to display code action buttons in the editor toolbar.
591    ///
592    /// Default: false
593    pub code_actions: Option<bool>,
594}
595
596/// Scrollbar related settings
597#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Default)]
598pub struct ScrollbarContent {
599    /// When to show the scrollbar in the editor.
600    ///
601    /// Default: auto
602    pub show: Option<ShowScrollbar>,
603    /// Whether to show git diff indicators in the scrollbar.
604    ///
605    /// Default: true
606    pub git_diff: Option<bool>,
607    /// Whether to show buffer search result indicators in the scrollbar.
608    ///
609    /// Default: true
610    pub search_results: Option<bool>,
611    /// Whether to show selected text occurrences in the scrollbar.
612    ///
613    /// Default: true
614    pub selected_text: Option<bool>,
615    /// Whether to show selected symbol occurrences in the scrollbar.
616    ///
617    /// Default: true
618    pub selected_symbol: Option<bool>,
619    /// Which diagnostic indicators to show in the scrollbar:
620    ///
621    /// Default: all
622    pub diagnostics: Option<ScrollbarDiagnostics>,
623    /// Whether to show cursor positions in the scrollbar.
624    ///
625    /// Default: true
626    pub cursors: Option<bool>,
627    /// Forcefully enable or disable the scrollbar for each axis
628    pub axes: Option<ScrollbarAxesContent>,
629}
630
631/// Minimap related settings
632#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
633pub struct MinimapContent {
634    /// When to show the minimap in the editor.
635    ///
636    /// Default: never
637    pub show: Option<ShowMinimap>,
638
639    /// Where to show the minimap in the editor.
640    ///
641    /// Default: [`DisplayIn::ActiveEditor`]
642    pub display_in: Option<DisplayIn>,
643
644    /// When to show the minimap thumb.
645    ///
646    /// Default: always
647    pub thumb: Option<MinimapThumb>,
648
649    /// Defines the border style for the minimap's scrollbar thumb.
650    ///
651    /// Default: left_open
652    pub thumb_border: Option<MinimapThumbBorder>,
653
654    /// How to highlight the current line in the minimap.
655    ///
656    /// Default: inherits editor line highlights setting
657    pub current_line_highlight: Option<Option<CurrentLineHighlight>>,
658
659    /// Maximum number of columns to display in the minimap.
660    ///
661    /// Default: 80
662    pub max_width_columns: Option<num::NonZeroU32>,
663}
664
665/// Forcefully enable or disable the scrollbar for each axis
666#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Default)]
667pub struct ScrollbarAxesContent {
668    /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
669    ///
670    /// Default: true
671    horizontal: Option<bool>,
672
673    /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
674    ///
675    /// Default: true
676    vertical: Option<bool>,
677}
678
679/// Gutter related settings
680#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
681pub struct GutterContent {
682    /// Whether to show line numbers in the gutter.
683    ///
684    /// Default: true
685    pub line_numbers: Option<bool>,
686    /// Minimum number of characters to reserve space for in the gutter.
687    ///
688    /// Default: 4
689    pub min_line_number_digits: Option<usize>,
690    /// Whether to show runnable buttons in the gutter.
691    ///
692    /// Default: true
693    pub runnables: Option<bool>,
694    /// Whether to show breakpoints in the gutter.
695    ///
696    /// Default: true
697    pub breakpoints: Option<bool>,
698    /// Whether to show fold buttons in the gutter.
699    ///
700    /// Default: true
701    pub folds: Option<bool>,
702}
703
704impl EditorSettings {
705    pub fn jupyter_enabled(cx: &App) -> bool {
706        EditorSettings::get_global(cx).jupyter.enabled
707    }
708}
709
710impl Settings for EditorSettings {
711    const KEY: Option<&'static str> = None;
712
713    type FileContent = EditorSettingsContent;
714
715    fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> anyhow::Result<Self> {
716        sources.json_merge()
717    }
718
719    fn import_from_vscode(vscode: &VsCodeSettings, current: &mut Self::FileContent) {
720        vscode.enum_setting(
721            "editor.cursorBlinking",
722            &mut current.cursor_blink,
723            |s| match s {
724                "blink" | "phase" | "expand" | "smooth" => Some(true),
725                "solid" => Some(false),
726                _ => None,
727            },
728        );
729        vscode.enum_setting(
730            "editor.cursorStyle",
731            &mut current.cursor_shape,
732            |s| match s {
733                "block" => Some(CursorShape::Block),
734                "block-outline" => Some(CursorShape::Hollow),
735                "line" | "line-thin" => Some(CursorShape::Bar),
736                "underline" | "underline-thin" => Some(CursorShape::Underline),
737                _ => None,
738            },
739        );
740
741        vscode.enum_setting(
742            "editor.renderLineHighlight",
743            &mut current.current_line_highlight,
744            |s| match s {
745                "gutter" => Some(CurrentLineHighlight::Gutter),
746                "line" => Some(CurrentLineHighlight::Line),
747                "all" => Some(CurrentLineHighlight::All),
748                _ => None,
749            },
750        );
751
752        vscode.bool_setting(
753            "editor.selectionHighlight",
754            &mut current.selection_highlight,
755        );
756        vscode.bool_setting("editor.hover.enabled", &mut current.hover_popover_enabled);
757        vscode.u64_setting("editor.hover.delay", &mut current.hover_popover_delay);
758
759        let mut gutter = GutterContent::default();
760        vscode.enum_setting(
761            "editor.showFoldingControls",
762            &mut gutter.folds,
763            |s| match s {
764                "always" | "mouseover" => Some(true),
765                "never" => Some(false),
766                _ => None,
767            },
768        );
769        vscode.enum_setting(
770            "editor.lineNumbers",
771            &mut gutter.line_numbers,
772            |s| match s {
773                "on" | "relative" => Some(true),
774                "off" => Some(false),
775                _ => None,
776            },
777        );
778        if let Some(old_gutter) = current.gutter.as_mut() {
779            if gutter.folds.is_some() {
780                old_gutter.folds = gutter.folds
781            }
782            if gutter.line_numbers.is_some() {
783                old_gutter.line_numbers = gutter.line_numbers
784            }
785        } else {
786            if gutter != GutterContent::default() {
787                current.gutter = Some(gutter)
788            }
789        }
790        if let Some(b) = vscode.read_bool("editor.scrollBeyondLastLine") {
791            current.scroll_beyond_last_line = Some(if b {
792                ScrollBeyondLastLine::OnePage
793            } else {
794                ScrollBeyondLastLine::Off
795            })
796        }
797
798        let mut scrollbar_axes = ScrollbarAxesContent::default();
799        vscode.enum_setting(
800            "editor.scrollbar.horizontal",
801            &mut scrollbar_axes.horizontal,
802            |s| match s {
803                "auto" | "visible" => Some(true),
804                "hidden" => Some(false),
805                _ => None,
806            },
807        );
808        vscode.enum_setting(
809            "editor.scrollbar.vertical",
810            &mut scrollbar_axes.horizontal,
811            |s| match s {
812                "auto" | "visible" => Some(true),
813                "hidden" => Some(false),
814                _ => None,
815            },
816        );
817
818        if scrollbar_axes != ScrollbarAxesContent::default() {
819            let scrollbar_settings = current.scrollbar.get_or_insert_default();
820            let axes_settings = scrollbar_settings.axes.get_or_insert_default();
821
822            if let Some(vertical) = scrollbar_axes.vertical {
823                axes_settings.vertical = Some(vertical);
824            }
825            if let Some(horizontal) = scrollbar_axes.horizontal {
826                axes_settings.horizontal = Some(horizontal);
827            }
828        }
829
830        // TODO: check if this does the int->float conversion?
831        vscode.f32_setting(
832            "editor.cursorSurroundingLines",
833            &mut current.vertical_scroll_margin,
834        );
835        vscode.f32_setting(
836            "editor.mouseWheelScrollSensitivity",
837            &mut current.scroll_sensitivity,
838        );
839        vscode.f32_setting(
840            "editor.fastScrollSensitivity",
841            &mut current.fast_scroll_sensitivity,
842        );
843        if Some("relative") == vscode.read_string("editor.lineNumbers") {
844            current.relative_line_numbers = Some(true);
845        }
846
847        vscode.enum_setting(
848            "editor.find.seedSearchStringFromSelection",
849            &mut current.seed_search_query_from_cursor,
850            |s| match s {
851                "always" => Some(SeedQuerySetting::Always),
852                "selection" => Some(SeedQuerySetting::Selection),
853                "never" => Some(SeedQuerySetting::Never),
854                _ => None,
855            },
856        );
857        vscode.bool_setting("search.smartCase", &mut current.use_smartcase_search);
858        vscode.enum_setting(
859            "editor.multiCursorModifier",
860            &mut current.multi_cursor_modifier,
861            |s| match s {
862                "ctrlCmd" => Some(MultiCursorModifier::CmdOrCtrl),
863                "alt" => Some(MultiCursorModifier::Alt),
864                _ => None,
865            },
866        );
867
868        vscode.bool_setting(
869            "editor.parameterHints.enabled",
870            &mut current.auto_signature_help,
871        );
872        vscode.bool_setting(
873            "editor.parameterHints.enabled",
874            &mut current.show_signature_help_after_edits,
875        );
876
877        if let Some(use_ignored) = vscode.read_bool("search.useIgnoreFiles") {
878            let search = current.search.get_or_insert_default();
879            search.include_ignored = use_ignored;
880        }
881
882        let mut minimap = MinimapContent::default();
883        let minimap_enabled = vscode.read_bool("editor.minimap.enabled").unwrap_or(true);
884        let autohide = vscode.read_bool("editor.minimap.autohide");
885        let mut max_width_columns: Option<u32> = None;
886        vscode.u32_setting("editor.minimap.maxColumn", &mut max_width_columns);
887        if minimap_enabled {
888            if let Some(false) = autohide {
889                minimap.show = Some(ShowMinimap::Always);
890            } else {
891                minimap.show = Some(ShowMinimap::Auto);
892            }
893        } else {
894            minimap.show = Some(ShowMinimap::Never);
895        }
896        if let Some(max_width_columns) = max_width_columns {
897            minimap.max_width_columns = NonZeroU32::new(max_width_columns);
898        }
899
900        vscode.enum_setting(
901            "editor.minimap.showSlider",
902            &mut minimap.thumb,
903            |s| match s {
904                "always" => Some(MinimapThumb::Always),
905                "mouseover" => Some(MinimapThumb::Hover),
906                _ => None,
907            },
908        );
909
910        if minimap != MinimapContent::default() {
911            current.minimap = Some(minimap)
912        }
913    }
914}