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