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