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