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