editor.rs

  1use std::num;
  2
  3use collections::HashMap;
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6use serde_with::skip_serializing_none;
  7use settings_macros::MergeFrom;
  8
  9use crate::{DiagnosticSeverityContent, ShowScrollbar};
 10
 11#[skip_serializing_none]
 12#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
 13pub struct EditorSettingsContent {
 14    /// Whether the cursor blinks in the editor.
 15    ///
 16    /// Default: true
 17    pub cursor_blink: Option<bool>,
 18    /// Cursor shape for the default editor.
 19    /// Can be "bar", "block", "underline", or "hollow".
 20    ///
 21    /// Default: bar
 22    pub cursor_shape: Option<CursorShape>,
 23    /// Determines when the mouse cursor should be hidden in an editor or input box.
 24    ///
 25    /// Default: on_typing_and_movement
 26    pub hide_mouse: Option<HideMouseMode>,
 27    /// Determines how snippets are sorted relative to other completion items.
 28    ///
 29    /// Default: inline
 30    pub snippet_sort_order: Option<SnippetSortOrder>,
 31    /// How to highlight the current line in the editor.
 32    ///
 33    /// Default: all
 34    pub current_line_highlight: Option<CurrentLineHighlight>,
 35    /// Whether to highlight all occurrences of the selected text in an editor.
 36    ///
 37    /// Default: true
 38    pub selection_highlight: Option<bool>,
 39    /// Whether the text selection should have rounded corners.
 40    ///
 41    /// Default: true
 42    pub rounded_selection: Option<bool>,
 43    /// The debounce delay before querying highlights from the language
 44    /// server based on the current cursor location.
 45    ///
 46    /// Default: 75
 47    pub lsp_highlight_debounce: Option<u64>,
 48    /// Whether to show the informational hover box when moving the mouse
 49    /// over symbols in the editor.
 50    ///
 51    /// Default: true
 52    pub hover_popover_enabled: Option<bool>,
 53    /// Time to wait in milliseconds before showing the informational hover box.
 54    ///
 55    /// Default: 300
 56    pub hover_popover_delay: Option<u64>,
 57    /// Status bar related settings
 58    pub status_bar: Option<StatusBarContent>,
 59    /// Toolbar related settings
 60    pub toolbar: Option<ToolbarContent>,
 61    /// Scrollbar related settings
 62    pub scrollbar: Option<ScrollbarContent>,
 63    /// Minimap related settings
 64    pub minimap: Option<MinimapContent>,
 65    /// Gutter related settings
 66    pub gutter: Option<GutterContent>,
 67    /// Whether the editor will scroll beyond the last line.
 68    ///
 69    /// Default: one_page
 70    pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
 71    /// The number of lines to keep above/below the cursor when auto-scrolling.
 72    ///
 73    /// Default: 3.
 74    pub vertical_scroll_margin: Option<f32>,
 75    /// Whether to scroll when clicking near the edge of the visible text area.
 76    ///
 77    /// Default: false
 78    pub autoscroll_on_clicks: Option<bool>,
 79    /// The number of characters to keep on either side when scrolling with the mouse.
 80    ///
 81    /// Default: 5.
 82    pub horizontal_scroll_margin: Option<f32>,
 83    /// Scroll sensitivity multiplier. This multiplier is applied
 84    /// to both the horizontal and vertical delta values while scrolling.
 85    ///
 86    /// Default: 1.0
 87    pub scroll_sensitivity: Option<f32>,
 88    /// Scroll sensitivity multiplier for fast scrolling. This multiplier is applied
 89    /// to both the horizontal and vertical delta values while scrolling. Fast scrolling
 90    /// happens when a user holds the alt or option key while scrolling.
 91    ///
 92    /// Default: 4.0
 93    pub fast_scroll_sensitivity: Option<f32>,
 94    /// Whether the line numbers on editors gutter are relative or not.
 95    ///
 96    /// Default: false
 97    pub relative_line_numbers: Option<bool>,
 98    /// When to populate a new search's query based on the text under the cursor.
 99    ///
100    /// Default: always
101    pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
102    pub use_smartcase_search: Option<bool>,
103    /// 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.
104    ///
105    /// Default: alt
106    pub multi_cursor_modifier: Option<MultiCursorModifier>,
107    /// Hide the values of variables in `private` files, as defined by the
108    /// private_files setting. This only changes the visual representation,
109    /// the values are still present in the file and can be selected / copied / pasted
110    ///
111    /// Default: false
112    pub redact_private_values: Option<bool>,
113
114    /// How many lines to expand the multibuffer excerpts by default
115    ///
116    /// Default: 3
117    pub expand_excerpt_lines: Option<u32>,
118
119    /// How many lines of context to provide in multibuffer excerpts by default
120    ///
121    /// Default: 2
122    pub excerpt_context_lines: Option<u32>,
123
124    /// Whether to enable middle-click paste on Linux
125    ///
126    /// Default: true
127    pub middle_click_paste: Option<bool>,
128
129    /// What to do when multibuffer is double clicked in some of its excerpts
130    /// (parts of singleton buffers).
131    ///
132    /// Default: select
133    pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
134    /// Whether the editor search results will loop
135    ///
136    /// Default: true
137    pub search_wrap: Option<bool>,
138
139    /// Defaults to use when opening a new buffer and project search items.
140    ///
141    /// Default: nothing is enabled
142    pub search: Option<SearchSettingsContent>,
143
144    /// Whether to automatically show a signature help pop-up or not.
145    ///
146    /// Default: false
147    pub auto_signature_help: Option<bool>,
148
149    /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
150    ///
151    /// Default: false
152    pub show_signature_help_after_edits: Option<bool>,
153    /// The minimum APCA perceptual contrast to maintain when
154    /// rendering text over highlight backgrounds in the editor.
155    ///
156    /// Values range from 0 to 106. Set to 0 to disable adjustments.
157    /// Default: 45
158    pub minimum_contrast_for_highlights: Option<f32>,
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// Status bar related settings
197#[skip_serializing_none]
198#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
199pub struct StatusBarContent {
200    /// Whether to display the active language button in the status bar.
201    ///
202    /// Default: true
203    pub active_language_button: Option<bool>,
204    /// Whether to show the cursor position button in the status bar.
205    ///
206    /// Default: true
207    pub cursor_position_button: Option<bool>,
208}
209
210// Toolbar related settings
211#[skip_serializing_none]
212#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
213pub struct ToolbarContent {
214    /// Whether to display breadcrumbs in the editor toolbar.
215    ///
216    /// Default: true
217    pub breadcrumbs: Option<bool>,
218    /// Whether to display quick action buttons in the editor toolbar.
219    ///
220    /// Default: true
221    pub quick_actions: Option<bool>,
222    /// Whether to show the selections menu in the editor toolbar.
223    ///
224    /// Default: true
225    pub selections_menu: Option<bool>,
226    /// Whether to display Agent review buttons in the editor toolbar.
227    /// Only applicable while reviewing a file edited by the Agent.
228    ///
229    /// Default: true
230    pub agent_review: Option<bool>,
231    /// Whether to display code action buttons in the editor toolbar.
232    ///
233    /// Default: false
234    pub code_actions: Option<bool>,
235}
236
237/// Scrollbar related settings
238#[skip_serializing_none]
239#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)]
240pub struct ScrollbarContent {
241    /// When to show the scrollbar in the editor.
242    ///
243    /// Default: auto
244    pub show: Option<ShowScrollbar>,
245    /// Whether to show git diff indicators in the scrollbar.
246    ///
247    /// Default: true
248    pub git_diff: Option<bool>,
249    /// Whether to show buffer search result indicators in the scrollbar.
250    ///
251    /// Default: true
252    pub search_results: Option<bool>,
253    /// Whether to show selected text occurrences in the scrollbar.
254    ///
255    /// Default: true
256    pub selected_text: Option<bool>,
257    /// Whether to show selected symbol occurrences in the scrollbar.
258    ///
259    /// Default: true
260    pub selected_symbol: Option<bool>,
261    /// Which diagnostic indicators to show in the scrollbar:
262    ///
263    /// Default: all
264    pub diagnostics: Option<ScrollbarDiagnostics>,
265    /// Whether to show cursor positions in the scrollbar.
266    ///
267    /// Default: true
268    pub cursors: Option<bool>,
269    /// Forcefully enable or disable the scrollbar for each axis
270    pub axes: Option<ScrollbarAxesContent>,
271}
272
273/// Minimap related settings
274#[skip_serializing_none]
275#[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
276pub struct MinimapContent {
277    /// When to show the minimap in the editor.
278    ///
279    /// Default: never
280    pub show: Option<ShowMinimap>,
281
282    /// Where to show the minimap in the editor.
283    ///
284    /// Default: [`DisplayIn::ActiveEditor`]
285    pub display_in: Option<DisplayIn>,
286
287    /// When to show the minimap thumb.
288    ///
289    /// Default: always
290    pub thumb: Option<MinimapThumb>,
291
292    /// Defines the border style for the minimap's scrollbar thumb.
293    ///
294    /// Default: left_open
295    pub thumb_border: Option<MinimapThumbBorder>,
296
297    /// How to highlight the current line in the minimap.
298    ///
299    /// Default: inherits editor line highlights setting
300    pub current_line_highlight: Option<CurrentLineHighlight>,
301
302    /// Maximum number of columns to display in the minimap.
303    ///
304    /// Default: 80
305    pub max_width_columns: Option<num::NonZeroU32>,
306}
307
308/// Forcefully enable or disable the scrollbar for each axis
309#[skip_serializing_none]
310#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)]
311pub struct ScrollbarAxesContent {
312    /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
313    ///
314    /// Default: true
315    pub horizontal: Option<bool>,
316
317    /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
318    ///
319    /// Default: true
320    pub vertical: Option<bool>,
321}
322
323/// Gutter related settings
324#[skip_serializing_none]
325#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
326pub struct GutterContent {
327    /// Whether to show line numbers in the gutter.
328    ///
329    /// Default: true
330    pub line_numbers: Option<bool>,
331    /// Minimum number of characters to reserve space for in the gutter.
332    ///
333    /// Default: 4
334    pub min_line_number_digits: Option<usize>,
335    /// Whether to show runnable buttons in the gutter.
336    ///
337    /// Default: true
338    pub runnables: Option<bool>,
339    /// Whether to show breakpoints in the gutter.
340    ///
341    /// Default: true
342    pub breakpoints: Option<bool>,
343    /// Whether to show fold buttons in the gutter.
344    ///
345    /// Default: true
346    pub folds: Option<bool>,
347}
348
349/// How to render LSP `textDocument/documentColor` colors in the editor.
350#[derive(
351    Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom,
352)]
353#[serde(rename_all = "snake_case")]
354pub enum DocumentColorsRenderMode {
355    /// Do not query and render document colors.
356    None,
357    /// Render document colors as inlay hints near the color text.
358    #[default]
359    Inlay,
360    /// Draw a border around the color text.
361    Border,
362    /// Draw a background behind the color text.
363    Background,
364}
365
366#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
367#[serde(rename_all = "snake_case")]
368pub enum CurrentLineHighlight {
369    // Don't highlight the current line.
370    None,
371    // Highlight the gutter area.
372    Gutter,
373    // Highlight the editor area.
374    Line,
375    // Highlight the full line.
376    All,
377}
378
379/// When to populate a new search's query based on the text under the cursor.
380#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
381#[serde(rename_all = "snake_case")]
382pub enum SeedQuerySetting {
383    /// Always populate the search query with the word under the cursor.
384    Always,
385    /// Only populate the search query when there is text selected.
386    Selection,
387    /// Never populate the search query
388    Never,
389}
390
391/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
392#[derive(
393    Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom,
394)]
395#[serde(rename_all = "snake_case")]
396pub enum DoubleClickInMultibuffer {
397    /// Behave as a regular buffer and select the whole word.
398    #[default]
399    Select,
400    /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
401    /// Otherwise, behave as a regular buffer and select the whole word.
402    Open,
403}
404
405/// When to show the minimap thumb.
406///
407/// Default: always
408#[derive(
409    Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
410)]
411#[serde(rename_all = "snake_case")]
412pub enum MinimapThumb {
413    /// Show the minimap thumb only when the mouse is hovering over the minimap.
414    Hover,
415    /// Always show the minimap thumb.
416    #[default]
417    Always,
418}
419
420/// Defines the border style for the minimap's scrollbar thumb.
421///
422/// Default: left_open
423#[derive(
424    Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
425)]
426#[serde(rename_all = "snake_case")]
427pub enum MinimapThumbBorder {
428    /// Displays a border on all sides of the thumb.
429    Full,
430    /// Displays a border on all sides except the left side of the thumb.
431    #[default]
432    LeftOpen,
433    /// Displays a border on all sides except the right side of the thumb.
434    RightOpen,
435    /// Displays a border only on the left side of the thumb.
436    LeftOnly,
437    /// Displays the thumb without any border.
438    None,
439}
440
441/// Which diagnostic indicators to show in the scrollbar.
442///
443/// Default: all
444#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
445#[serde(rename_all = "lowercase")]
446pub enum ScrollbarDiagnostics {
447    /// Show all diagnostic levels: hint, information, warnings, error.
448    All,
449    /// Show only the following diagnostic levels: information, warning, error.
450    Information,
451    /// Show only the following diagnostic levels: warning, error.
452    Warning,
453    /// Show only the following diagnostic level: error.
454    Error,
455    /// Do not show diagnostics.
456    None,
457}
458
459/// The key to use for adding multiple cursors
460///
461/// Default: alt
462#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
463#[serde(rename_all = "snake_case")]
464pub enum MultiCursorModifier {
465    Alt,
466    #[serde(alias = "cmd", alias = "ctrl")]
467    CmdOrCtrl,
468}
469
470/// Whether the editor will scroll beyond the last line.
471///
472/// Default: one_page
473#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
474#[serde(rename_all = "snake_case")]
475pub enum ScrollBeyondLastLine {
476    /// The editor will not scroll beyond the last line.
477    Off,
478
479    /// The editor will scroll beyond the last line by one page.
480    OnePage,
481
482    /// The editor will scroll beyond the last line by the same number of lines as vertical_scroll_margin.
483    VerticalScrollMargin,
484}
485
486/// The shape of a selection cursor.
487#[derive(
488    Copy,
489    Clone,
490    Debug,
491    Default,
492    Serialize,
493    Deserialize,
494    PartialEq,
495    Eq,
496    JsonSchema,
497    MergeFrom,
498    strum::VariantArray,
499    strum::VariantNames,
500)]
501#[serde(rename_all = "snake_case")]
502pub enum CursorShape {
503    /// A vertical bar
504    #[default]
505    Bar,
506    /// A block that surrounds the following character
507    Block,
508    /// An underline that runs along the following character
509    Underline,
510    /// A box drawn around the following character
511    Hollow,
512}
513
514/// What to do when go to definition yields no results.
515#[derive(
516    Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom,
517)]
518#[serde(rename_all = "snake_case")]
519pub enum GoToDefinitionFallback {
520    /// Disables the fallback.
521    None,
522    /// Looks up references of the same symbol instead.
523    #[default]
524    FindAllReferences,
525}
526
527/// Determines when the mouse cursor should be hidden in an editor or input box.
528///
529/// Default: on_typing_and_movement
530#[derive(
531    Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom,
532)]
533#[serde(rename_all = "snake_case")]
534pub enum HideMouseMode {
535    /// Never hide the mouse cursor
536    Never,
537    /// Hide only when typing
538    OnTyping,
539    /// Hide on both typing and cursor movement
540    #[default]
541    OnTypingAndMovement,
542}
543
544/// Determines how snippets are sorted relative to other completion items.
545///
546/// Default: inline
547#[derive(
548    Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom,
549)]
550#[serde(rename_all = "snake_case")]
551pub enum SnippetSortOrder {
552    /// Place snippets at the top of the completion list
553    Top,
554    /// Sort snippets normally using the default comparison logic
555    #[default]
556    Inline,
557    /// Place snippets at the bottom of the completion list
558    Bottom,
559    /// Do not show snippets in the completion list
560    None,
561}
562
563/// Default options for buffer and project search items.
564#[skip_serializing_none]
565#[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
566pub struct SearchSettingsContent {
567    /// Whether to show the project search button in the status bar.
568    pub button: Option<bool>,
569    pub whole_word: Option<bool>,
570    pub case_sensitive: Option<bool>,
571    pub include_ignored: Option<bool>,
572    pub regex: Option<bool>,
573}
574
575#[skip_serializing_none]
576#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
577#[serde(rename_all = "snake_case")]
578pub struct JupyterContent {
579    /// Whether the Jupyter feature is enabled.
580    ///
581    /// Default: true
582    pub enabled: Option<bool>,
583
584    /// Default kernels to select for each language.
585    ///
586    /// Default: `{}`
587    pub kernel_selections: Option<HashMap<String, String>>,
588}
589
590/// Whether to allow drag and drop text selection in buffer.
591#[skip_serializing_none]
592#[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
593pub struct DragAndDropSelectionContent {
594    /// When true, enables drag and drop text selection in buffer.
595    ///
596    /// Default: true
597    pub enabled: Option<bool>,
598
599    /// The delay in milliseconds that must elapse before drag and drop is allowed. Otherwise, a new text selection is created.
600    ///
601    /// Default: 300
602    pub delay: Option<u64>,
603}
604
605/// When to show the minimap in the editor.
606///
607/// Default: never
608#[derive(
609    Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
610)]
611#[serde(rename_all = "snake_case")]
612pub enum ShowMinimap {
613    /// Follow the visibility of the scrollbar.
614    Auto,
615    /// Always show the minimap.
616    Always,
617    /// Never show the minimap.
618    #[default]
619    Never,
620}
621
622/// Where to show the minimap in the editor.
623///
624/// Default: all_editors
625#[derive(
626    Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
627)]
628#[serde(rename_all = "snake_case")]
629pub enum DisplayIn {
630    /// Show on all open editors.
631    AllEditors,
632    /// Show the minimap on the active editor only.
633    #[default]
634    ActiveEditor,
635}