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