editor_settings.rs

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