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