editor_settings.rs

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