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