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