1use gpui::App;
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 selection_highlight: bool,
13 pub lsp_highlight_debounce: u64,
14 pub hover_popover_enabled: bool,
15 pub hover_popover_delay: u64,
16 pub toolbar: Toolbar,
17 pub scrollbar: Scrollbar,
18 pub gutter: Gutter,
19 pub scroll_beyond_last_line: ScrollBeyondLastLine,
20 pub vertical_scroll_margin: f32,
21 pub autoscroll_on_clicks: bool,
22 pub horizontal_scroll_margin: f32,
23 pub scroll_sensitivity: f32,
24 pub relative_line_numbers: bool,
25 pub seed_search_query_from_cursor: SeedQuerySetting,
26 pub use_smartcase_search: bool,
27 pub multi_cursor_modifier: MultiCursorModifier,
28 pub redact_private_values: bool,
29 pub expand_excerpt_lines: u32,
30 pub middle_click_paste: bool,
31 #[serde(default)]
32 pub double_click_in_multibuffer: DoubleClickInMultibuffer,
33 pub search_wrap: bool,
34 #[serde(default)]
35 pub search: SearchSettings,
36 pub auto_signature_help: bool,
37 pub show_signature_help_after_edits: bool,
38 #[serde(default)]
39 pub go_to_definition_fallback: GoToDefinitionFallback,
40 pub jupyter: Jupyter,
41 pub hide_mouse: Option<HideMouseMode>,
42 pub snippet_sort_order: SnippetSortOrder,
43}
44
45#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
46#[serde(rename_all = "snake_case")]
47pub enum CurrentLineHighlight {
48 // Don't highlight the current line.
49 None,
50 // Highlight the gutter area.
51 Gutter,
52 // Highlight the editor area.
53 Line,
54 // Highlight the full line.
55 All,
56}
57
58/// When to populate a new search's query based on the text under the cursor.
59#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
60#[serde(rename_all = "snake_case")]
61pub enum SeedQuerySetting {
62 /// Always populate the search query with the word under the cursor.
63 Always,
64 /// Only populate the search query when there is text selected.
65 Selection,
66 /// Never populate the search query
67 Never,
68}
69
70/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
71#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
72#[serde(rename_all = "snake_case")]
73pub enum DoubleClickInMultibuffer {
74 /// Behave as a regular buffer and select the whole word.
75 #[default]
76 Select,
77 /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
78 /// Otherwise, behave as a regular buffer and select the whole word.
79 Open,
80}
81
82#[derive(Debug, Clone, Deserialize)]
83pub struct Jupyter {
84 /// Whether the Jupyter feature is enabled.
85 ///
86 /// Default: true
87 pub enabled: bool,
88}
89
90#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
91#[serde(rename_all = "snake_case")]
92pub struct JupyterContent {
93 /// Whether the Jupyter feature is enabled.
94 ///
95 /// Default: true
96 pub enabled: Option<bool>,
97}
98
99#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
100pub struct Toolbar {
101 pub breadcrumbs: bool,
102 pub quick_actions: bool,
103 pub selections_menu: bool,
104}
105
106#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
107pub struct Scrollbar {
108 pub show: ShowScrollbar,
109 pub git_diff: bool,
110 pub selected_text: bool,
111 pub selected_symbol: bool,
112 pub search_results: bool,
113 pub diagnostics: ScrollbarDiagnostics,
114 pub cursors: bool,
115 pub axes: ScrollbarAxes,
116}
117
118#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
119pub struct Gutter {
120 pub line_numbers: bool,
121 pub code_actions: bool,
122 pub runnables: bool,
123 pub breakpoints: bool,
124 pub folds: bool,
125}
126
127/// When to show the scrollbar in the editor.
128///
129/// Default: auto
130#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
131#[serde(rename_all = "snake_case")]
132pub enum ShowScrollbar {
133 /// Show the scrollbar if there's important information or
134 /// follow the system's configured behavior.
135 Auto,
136 /// Match the system's configured behavior.
137 System,
138 /// Always show the scrollbar.
139 Always,
140 /// Never show the scrollbar.
141 Never,
142}
143
144/// Forcefully enable or disable the scrollbar for each axis
145#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
146#[serde(rename_all = "lowercase")]
147pub struct ScrollbarAxes {
148 /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
149 ///
150 /// Default: true
151 pub horizontal: bool,
152
153 /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
154 ///
155 /// Default: true
156 pub vertical: bool,
157}
158
159/// Which diagnostic indicators to show in the scrollbar.
160///
161/// Default: all
162#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
163#[serde(rename_all = "lowercase")]
164pub enum ScrollbarDiagnostics {
165 /// Show all diagnostic levels: hint, information, warnings, error.
166 All,
167 /// Show only the following diagnostic levels: information, warning, error.
168 Information,
169 /// Show only the following diagnostic levels: warning, error.
170 Warning,
171 /// Show only the following diagnostic level: error.
172 Error,
173 /// Do not show diagnostics.
174 None,
175}
176
177/// The key to use for adding multiple cursors
178///
179/// Default: alt
180#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
181#[serde(rename_all = "snake_case")]
182pub enum MultiCursorModifier {
183 Alt,
184 #[serde(alias = "cmd", alias = "ctrl")]
185 CmdOrCtrl,
186}
187
188/// Whether the editor will scroll beyond the last line.
189///
190/// Default: one_page
191#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
192#[serde(rename_all = "snake_case")]
193pub enum ScrollBeyondLastLine {
194 /// The editor will not scroll beyond the last line.
195 Off,
196
197 /// The editor will scroll beyond the last line by one page.
198 OnePage,
199
200 /// The editor will scroll beyond the last line by the same number of lines as vertical_scroll_margin.
201 VerticalScrollMargin,
202}
203
204/// Default options for buffer and project search items.
205#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
206pub struct SearchSettings {
207 #[serde(default)]
208 pub whole_word: bool,
209 #[serde(default)]
210 pub case_sensitive: bool,
211 #[serde(default)]
212 pub include_ignored: bool,
213 #[serde(default)]
214 pub regex: bool,
215}
216
217/// What to do when go to definition yields no results.
218#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
219#[serde(rename_all = "snake_case")]
220pub enum GoToDefinitionFallback {
221 /// Disables the fallback.
222 None,
223 /// Looks up references of the same symbol instead.
224 #[default]
225 FindAllReferences,
226}
227
228/// Determines when the mouse cursor should be hidden in an editor or input box.
229///
230/// Default: on_typing_and_movement
231#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
232#[serde(rename_all = "snake_case")]
233pub enum HideMouseMode {
234 /// Never hide the mouse cursor
235 Never,
236 /// Hide only when typing
237 OnTyping,
238 /// Hide on both typing and cursor movement
239 #[default]
240 OnTypingAndMovement,
241}
242
243/// Determines how snippets are sorted relative to other completion items.
244///
245/// Default: inline
246#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
247#[serde(rename_all = "snake_case")]
248pub enum SnippetSortOrder {
249 /// Place snippets at the top of the completion list
250 Top,
251 /// Sort snippets normally using the default comparison logic
252 #[default]
253 Inline,
254 /// Place snippets at the bottom of the completion list
255 Bottom,
256}
257
258#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
259pub struct EditorSettingsContent {
260 /// Whether the cursor blinks in the editor.
261 ///
262 /// Default: true
263 pub cursor_blink: Option<bool>,
264 /// Cursor shape for the default editor.
265 /// Can be "bar", "block", "underline", or "hollow".
266 ///
267 /// Default: None
268 pub cursor_shape: Option<CursorShape>,
269 /// Determines when the mouse cursor should be hidden in an editor or input box.
270 ///
271 /// Default: on_typing_and_movement
272 pub hide_mouse: Option<HideMouseMode>,
273 /// Determines how snippets are sorted relative to other completion items.
274 ///
275 /// Default: inline
276 pub snippet_sort_order: Option<SnippetSortOrder>,
277 /// How to highlight the current line in the editor.
278 ///
279 /// Default: all
280 pub current_line_highlight: Option<CurrentLineHighlight>,
281 /// Whether to highlight all occurrences of the selected text in an editor.
282 ///
283 /// Default: true
284 pub selection_highlight: Option<bool>,
285 /// The debounce delay before querying highlights from the language
286 /// server based on the current cursor location.
287 ///
288 /// Default: 75
289 pub lsp_highlight_debounce: Option<u64>,
290 /// Whether to show the informational hover box when moving the mouse
291 /// over symbols in the editor.
292 ///
293 /// Default: true
294 pub hover_popover_enabled: Option<bool>,
295 /// Time to wait before showing the informational hover box
296 ///
297 /// Default: 350
298 pub hover_popover_delay: Option<u64>,
299 /// Toolbar related settings
300 pub toolbar: Option<ToolbarContent>,
301 /// Scrollbar related settings
302 pub scrollbar: Option<ScrollbarContent>,
303 /// Gutter related settings
304 pub gutter: Option<GutterContent>,
305 /// Whether the editor will scroll beyond the last line.
306 ///
307 /// Default: one_page
308 pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
309 /// The number of lines to keep above/below the cursor when auto-scrolling.
310 ///
311 /// Default: 3.
312 pub vertical_scroll_margin: Option<f32>,
313 /// Whether to scroll when clicking near the edge of the visible text area.
314 ///
315 /// Default: false
316 pub autoscroll_on_clicks: Option<bool>,
317 /// The number of characters to keep on either side when scrolling with the mouse.
318 ///
319 /// Default: 5.
320 pub horizontal_scroll_margin: Option<f32>,
321 /// Scroll sensitivity multiplier. This multiplier is applied
322 /// to both the horizontal and vertical delta values while scrolling.
323 ///
324 /// Default: 1.0
325 pub scroll_sensitivity: Option<f32>,
326 /// Whether the line numbers on editors gutter are relative or not.
327 ///
328 /// Default: false
329 pub relative_line_numbers: Option<bool>,
330 /// When to populate a new search's query based on the text under the cursor.
331 ///
332 /// Default: always
333 pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
334 pub use_smartcase_search: Option<bool>,
335 /// The key to use for adding multiple cursors
336 ///
337 /// Default: alt
338 pub multi_cursor_modifier: Option<MultiCursorModifier>,
339 /// Hide the values of variables in `private` files, as defined by the
340 /// private_files setting. This only changes the visual representation,
341 /// the values are still present in the file and can be selected / copied / pasted
342 ///
343 /// Default: false
344 pub redact_private_values: Option<bool>,
345
346 /// How many lines to expand the multibuffer excerpts by default
347 ///
348 /// Default: 3
349 pub expand_excerpt_lines: Option<u32>,
350
351 /// Whether to enable middle-click paste on Linux
352 ///
353 /// Default: true
354 pub middle_click_paste: Option<bool>,
355
356 /// What to do when multibuffer is double clicked in some of its excerpts
357 /// (parts of singleton buffers).
358 ///
359 /// Default: select
360 pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
361 /// Whether the editor search results will loop
362 ///
363 /// Default: true
364 pub search_wrap: Option<bool>,
365
366 /// Defaults to use when opening a new buffer and project search items.
367 ///
368 /// Default: nothing is enabled
369 pub search: Option<SearchSettings>,
370
371 /// Whether to automatically show a signature help pop-up or not.
372 ///
373 /// Default: false
374 pub auto_signature_help: Option<bool>,
375
376 /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
377 ///
378 /// Default: false
379 pub show_signature_help_after_edits: Option<bool>,
380
381 /// Whether to follow-up empty go to definition responses from the language server or not.
382 /// `FindAllReferences` allows to look up references of the same symbol instead.
383 /// `None` disables the fallback.
384 ///
385 /// Default: FindAllReferences
386 pub go_to_definition_fallback: Option<GoToDefinitionFallback>,
387
388 /// Jupyter REPL settings.
389 pub jupyter: Option<JupyterContent>,
390}
391
392// Toolbar related settings
393#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
394pub struct ToolbarContent {
395 /// Whether to display breadcrumbs in the editor toolbar.
396 ///
397 /// Default: true
398 pub breadcrumbs: Option<bool>,
399 /// Whether to display quick action buttons in the editor toolbar.
400 ///
401 /// Default: true
402 pub quick_actions: Option<bool>,
403
404 /// Whether to show the selections menu in the editor toolbar
405 ///
406 /// Default: true
407 pub selections_menu: Option<bool>,
408}
409
410/// Scrollbar related settings
411#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
412pub struct ScrollbarContent {
413 /// When to show the scrollbar in the editor.
414 ///
415 /// Default: auto
416 pub show: Option<ShowScrollbar>,
417 /// Whether to show git diff indicators in the scrollbar.
418 ///
419 /// Default: true
420 pub git_diff: Option<bool>,
421 /// Whether to show buffer search result indicators in the scrollbar.
422 ///
423 /// Default: true
424 pub search_results: Option<bool>,
425 /// Whether to show selected text occurrences in the scrollbar.
426 ///
427 /// Default: true
428 pub selected_text: Option<bool>,
429 /// Whether to show selected symbol occurrences in the scrollbar.
430 ///
431 /// Default: true
432 pub selected_symbol: Option<bool>,
433 /// Which diagnostic indicators to show in the scrollbar:
434 ///
435 /// Default: all
436 pub diagnostics: Option<ScrollbarDiagnostics>,
437 /// Whether to show cursor positions in the scrollbar.
438 ///
439 /// Default: true
440 pub cursors: Option<bool>,
441 /// Forcefully enable or disable the scrollbar for each axis
442 pub axes: Option<ScrollbarAxesContent>,
443}
444
445/// Forcefully enable or disable the scrollbar for each axis
446#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
447pub struct ScrollbarAxesContent {
448 /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
449 ///
450 /// Default: true
451 horizontal: Option<bool>,
452
453 /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
454 ///
455 /// Default: true
456 vertical: Option<bool>,
457}
458
459/// Gutter related settings
460#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
461pub struct GutterContent {
462 /// Whether to show line numbers in the gutter.
463 ///
464 /// Default: true
465 pub line_numbers: Option<bool>,
466 /// Whether to show code action buttons in the gutter.
467 ///
468 /// Default: true
469 pub code_actions: Option<bool>,
470 /// Whether to show runnable buttons in the gutter.
471 ///
472 /// Default: true
473 pub runnables: Option<bool>,
474 /// Whether to show breakpoints in the gutter.
475 ///
476 /// Default: true
477 pub breakpoints: Option<bool>,
478 /// Whether to show fold buttons in the gutter.
479 ///
480 /// Default: true
481 pub folds: Option<bool>,
482}
483
484impl EditorSettings {
485 pub fn jupyter_enabled(cx: &App) -> bool {
486 EditorSettings::get_global(cx).jupyter.enabled
487 }
488}
489
490impl Settings for EditorSettings {
491 const KEY: Option<&'static str> = None;
492
493 type FileContent = EditorSettingsContent;
494
495 fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> anyhow::Result<Self> {
496 sources.json_merge()
497 }
498}