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