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