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