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