editor.rs

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