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