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