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