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