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