editor_settings.rs

  1use gpui::AppContext;
  2use schemars::JsonSchema;
  3use serde::{Deserialize, Serialize};
  4use settings::{Settings, SettingsSources};
  5
  6#[derive(Deserialize, Clone)]
  7pub struct EditorSettings {
  8    pub cursor_blink: bool,
  9    pub current_line_highlight: CurrentLineHighlight,
 10    pub hover_popover_enabled: bool,
 11    pub show_completions_on_input: bool,
 12    pub show_completion_documentation: bool,
 13    pub completion_documentation_secondary_query_debounce: u64,
 14    pub use_on_type_format: bool,
 15    pub toolbar: Toolbar,
 16    pub scrollbar: Scrollbar,
 17    pub gutter: Gutter,
 18    pub vertical_scroll_margin: f32,
 19    pub scroll_sensitivity: f32,
 20    pub relative_line_numbers: bool,
 21    pub seed_search_query_from_cursor: SeedQuerySetting,
 22    pub multi_cursor_modifier: MultiCursorModifier,
 23    pub redact_private_values: bool,
 24    pub expand_excerpt_lines: u32,
 25    #[serde(default)]
 26    pub double_click_in_multibuffer: DoubleClickInMultibuffer,
 27}
 28
 29#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 30#[serde(rename_all = "snake_case")]
 31pub enum CurrentLineHighlight {
 32    // Don't highlight the current line.
 33    None,
 34    // Highlight the gutter area.
 35    Gutter,
 36    // Highlight the editor area.
 37    Line,
 38    // Highlight the full line.
 39    All,
 40}
 41
 42/// When to populate a new search's query based on the text under the cursor.
 43#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 44#[serde(rename_all = "snake_case")]
 45pub enum SeedQuerySetting {
 46    /// Always populate the search query with the word under the cursor.
 47    Always,
 48    /// Only populate the search query when there is text selected.
 49    Selection,
 50    /// Never populate the search query
 51    Never,
 52}
 53
 54/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
 55#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 56#[serde(rename_all = "snake_case")]
 57pub enum DoubleClickInMultibuffer {
 58    /// Behave as a regular buffer and select the whole word.
 59    #[default]
 60    Select,
 61    /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
 62    /// Otherwise, behave as a regular buffer and select the whole word.
 63    Open,
 64}
 65
 66#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 67pub struct Toolbar {
 68    pub breadcrumbs: bool,
 69    pub quick_actions: bool,
 70    pub selections_menu: bool,
 71}
 72
 73#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 74pub struct Scrollbar {
 75    pub show: ShowScrollbar,
 76    pub git_diff: bool,
 77    pub selected_symbol: bool,
 78    pub search_results: bool,
 79    pub diagnostics: bool,
 80    pub cursors: bool,
 81}
 82
 83#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 84pub struct Gutter {
 85    pub line_numbers: bool,
 86    pub code_actions: bool,
 87    pub runnables: bool,
 88    pub folds: bool,
 89}
 90
 91/// When to show the scrollbar in the editor.
 92///
 93/// Default: auto
 94#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 95#[serde(rename_all = "snake_case")]
 96pub enum ShowScrollbar {
 97    /// Show the scrollbar if there's important information or
 98    /// follow the system's configured behavior.
 99    Auto,
100    /// Match the system's configured behavior.
101    System,
102    /// Always show the scrollbar.
103    Always,
104    /// Never show the scrollbar.
105    Never,
106}
107
108/// The key to use for adding multiple cursors
109///
110/// Default: alt
111#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
112#[serde(rename_all = "snake_case")]
113pub enum MultiCursorModifier {
114    Alt,
115    #[serde(alias = "cmd", alias = "ctrl")]
116    CmdOrCtrl,
117}
118
119#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
120pub struct EditorSettingsContent {
121    /// Whether the cursor blinks in the editor.
122    ///
123    /// Default: true
124    pub cursor_blink: Option<bool>,
125    /// How to highlight the current line in the editor.
126    ///
127    /// Default: all
128    pub current_line_highlight: Option<CurrentLineHighlight>,
129    /// Whether to show the informational hover box when moving the mouse
130    /// over symbols in the editor.
131    ///
132    /// Default: true
133    pub hover_popover_enabled: Option<bool>,
134
135    /// Whether to pop the completions menu while typing in an editor without
136    /// explicitly requesting it.
137    ///
138    /// Default: true
139    pub show_completions_on_input: Option<bool>,
140    /// Whether to display inline and alongside documentation for items in the
141    /// completions menu.
142    ///
143    /// Default: true
144    pub show_completion_documentation: Option<bool>,
145    /// The debounce delay before re-querying the language server for completion
146    /// documentation when not included in original completion list.
147    ///
148    /// Default: 300 ms
149    pub completion_documentation_secondary_query_debounce: Option<u64>,
150    /// Whether to use additional LSP queries to format (and amend) the code after
151    /// every "trigger" symbol input, defined by LSP server capabilities.
152    ///
153    /// Default: true
154    pub use_on_type_format: Option<bool>,
155    /// Toolbar related settings
156    pub toolbar: Option<ToolbarContent>,
157    /// Scrollbar related settings
158    pub scrollbar: Option<ScrollbarContent>,
159    /// Gutter related settings
160    pub gutter: Option<GutterContent>,
161    /// The number of lines to keep above/below the cursor when auto-scrolling.
162    ///
163    /// Default: 3.
164    pub vertical_scroll_margin: Option<f32>,
165    /// Scroll sensitivity multiplier. This multiplier is applied
166    /// to both the horizontal and vertical delta values while scrolling.
167    ///
168    /// Default: 1.0
169    pub scroll_sensitivity: Option<f32>,
170    /// Whether the line numbers on editors gutter are relative or not.
171    ///
172    /// Default: false
173    pub relative_line_numbers: Option<bool>,
174    /// When to populate a new search's query based on the text under the cursor.
175    ///
176    /// Default: always
177    pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
178    /// The key to use for adding multiple cursors
179    ///
180    /// Default: alt
181    pub multi_cursor_modifier: Option<MultiCursorModifier>,
182    /// Hide the values of variables in `private` files, as defined by the
183    /// private_files setting. This only changes the visual representation,
184    /// the values are still present in the file and can be selected / copied / pasted
185    ///
186    /// Default: false
187    pub redact_private_values: Option<bool>,
188
189    /// How many lines to expand the multibuffer excerpts by default
190    ///
191    /// Default: 3
192    pub expand_excerpt_lines: Option<u32>,
193
194    /// What to do when multibuffer is double clicked in some of its excerpts
195    /// (parts of singleton buffers).
196    ///
197    /// Default: select
198    pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
199}
200
201// Toolbar related settings
202#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
203pub struct ToolbarContent {
204    /// Whether to display breadcrumbs in the editor toolbar.
205    ///
206    /// Default: true
207    pub breadcrumbs: Option<bool>,
208    /// Whether to display quick action buttons in the editor toolbar.
209    ///
210    /// Default: true
211    pub quick_actions: Option<bool>,
212
213    /// Whether to show the selections menu in the editor toolbar
214    ///
215    /// Default: true
216    pub selections_menu: Option<bool>,
217}
218
219/// Scrollbar related settings
220#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
221pub struct ScrollbarContent {
222    /// When to show the scrollbar in the editor.
223    ///
224    /// Default: auto
225    pub show: Option<ShowScrollbar>,
226    /// Whether to show git diff indicators in the scrollbar.
227    ///
228    /// Default: true
229    pub git_diff: Option<bool>,
230    /// Whether to show buffer search result indicators in the scrollbar.
231    ///
232    /// Default: true
233    pub search_results: Option<bool>,
234    /// Whether to show selected symbol occurrences in the scrollbar.
235    ///
236    /// Default: true
237    pub selected_symbol: Option<bool>,
238    /// Whether to show diagnostic indicators in the scrollbar.
239    ///
240    /// Default: true
241    pub diagnostics: Option<bool>,
242    /// Whether to show cursor positions in the scrollbar.
243    ///
244    /// Default: true
245    pub cursors: Option<bool>,
246}
247
248/// Gutter related settings
249#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
250pub struct GutterContent {
251    /// Whether to show line numbers in the gutter.
252    ///
253    /// Default: true
254    pub line_numbers: Option<bool>,
255    /// Whether to show code action buttons in the gutter.
256    ///
257    /// Default: true
258    pub code_actions: Option<bool>,
259    /// Whether to show runnable buttons in the gutter.
260    ///
261    /// Default: true
262    pub runnables: Option<bool>,
263    /// Whether to show fold buttons in the gutter.
264    ///
265    /// Default: true
266    pub folds: Option<bool>,
267}
268
269impl Settings for EditorSettings {
270    const KEY: Option<&'static str> = None;
271
272    type FileContent = EditorSettingsContent;
273
274    fn load(
275        sources: SettingsSources<Self::FileContent>,
276        _: &mut AppContext,
277    ) -> anyhow::Result<Self> {
278        sources.json_merge()
279    }
280}