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