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 #[serde(default)]
40 pub go_to_definition_fallback: GoToDefinitionFallback,
41 pub jupyter: Jupyter,
42 pub hide_mouse: Option<HideMouseMode>,
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#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
244pub struct EditorSettingsContent {
245 /// Whether the cursor blinks in the editor.
246 ///
247 /// Default: true
248 pub cursor_blink: Option<bool>,
249 /// Cursor shape for the default editor.
250 /// Can be "bar", "block", "underline", or "hollow".
251 ///
252 /// Default: None
253 pub cursor_shape: Option<CursorShape>,
254 /// Determines when the mouse cursor should be hidden in an editor or input box.
255 ///
256 /// Default: on_typing_and_movement
257 pub hide_mouse: Option<HideMouseMode>,
258 /// How to highlight the current line in the editor.
259 ///
260 /// Default: all
261 pub current_line_highlight: Option<CurrentLineHighlight>,
262 /// Whether to highlight all occurrences of the selected text in an editor.
263 ///
264 /// Default: true
265 pub selection_highlight: Option<bool>,
266 /// The debounce delay before querying highlights based on the selected text.
267 ///
268 /// Default: 75
269 pub selection_highlight_debounce: Option<u64>,
270 /// The debounce delay before querying highlights from the language
271 /// server based on the current cursor location.
272 ///
273 /// Default: 75
274 pub lsp_highlight_debounce: Option<u64>,
275 /// Whether to show the informational hover box when moving the mouse
276 /// over symbols in the editor.
277 ///
278 /// Default: true
279 pub hover_popover_enabled: Option<bool>,
280 /// Time to wait before showing the informational hover box
281 ///
282 /// Default: 350
283 pub hover_popover_delay: Option<u64>,
284 /// Toolbar related settings
285 pub toolbar: Option<ToolbarContent>,
286 /// Scrollbar related settings
287 pub scrollbar: Option<ScrollbarContent>,
288 /// Gutter related settings
289 pub gutter: Option<GutterContent>,
290 /// Whether the editor will scroll beyond the last line.
291 ///
292 /// Default: one_page
293 pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
294 /// The number of lines to keep above/below the cursor when auto-scrolling.
295 ///
296 /// Default: 3.
297 pub vertical_scroll_margin: Option<f32>,
298 /// Whether to scroll when clicking near the edge of the visible text area.
299 ///
300 /// Default: false
301 pub autoscroll_on_clicks: Option<bool>,
302 /// The number of characters to keep on either side when scrolling with the mouse.
303 ///
304 /// Default: 5.
305 pub horizontal_scroll_margin: Option<f32>,
306 /// Scroll sensitivity multiplier. This multiplier is applied
307 /// to both the horizontal and vertical delta values while scrolling.
308 ///
309 /// Default: 1.0
310 pub scroll_sensitivity: Option<f32>,
311 /// Whether the line numbers on editors gutter are relative or not.
312 ///
313 /// Default: false
314 pub relative_line_numbers: Option<bool>,
315 /// When to populate a new search's query based on the text under the cursor.
316 ///
317 /// Default: always
318 pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
319 pub use_smartcase_search: Option<bool>,
320 /// The key to use for adding multiple cursors
321 ///
322 /// Default: alt
323 pub multi_cursor_modifier: Option<MultiCursorModifier>,
324 /// Hide the values of variables in `private` files, as defined by the
325 /// private_files setting. This only changes the visual representation,
326 /// the values are still present in the file and can be selected / copied / pasted
327 ///
328 /// Default: false
329 pub redact_private_values: Option<bool>,
330
331 /// How many lines to expand the multibuffer excerpts by default
332 ///
333 /// Default: 3
334 pub expand_excerpt_lines: Option<u32>,
335
336 /// Whether to enable middle-click paste on Linux
337 ///
338 /// Default: true
339 pub middle_click_paste: Option<bool>,
340
341 /// What to do when multibuffer is double clicked in some of its excerpts
342 /// (parts of singleton buffers).
343 ///
344 /// Default: select
345 pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
346 /// Whether the editor search results will loop
347 ///
348 /// Default: true
349 pub search_wrap: Option<bool>,
350
351 /// Defaults to use when opening a new buffer and project search items.
352 ///
353 /// Default: nothing is enabled
354 pub search: Option<SearchSettings>,
355
356 /// Whether to automatically show a signature help pop-up or not.
357 ///
358 /// Default: false
359 pub auto_signature_help: Option<bool>,
360
361 /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
362 ///
363 /// Default: false
364 pub show_signature_help_after_edits: Option<bool>,
365
366 /// Whether to follow-up empty go to definition responses from the language server or not.
367 /// `FindAllReferences` allows to look up references of the same symbol instead.
368 /// `None` disables the fallback.
369 ///
370 /// Default: FindAllReferences
371 pub go_to_definition_fallback: Option<GoToDefinitionFallback>,
372
373 /// Jupyter REPL settings.
374 pub jupyter: Option<JupyterContent>,
375}
376
377// Toolbar related settings
378#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
379pub struct ToolbarContent {
380 /// Whether to display breadcrumbs in the editor toolbar.
381 ///
382 /// Default: true
383 pub breadcrumbs: Option<bool>,
384 /// Whether to display quick action buttons in the editor toolbar.
385 ///
386 /// Default: true
387 pub quick_actions: Option<bool>,
388
389 /// Whether to show the selections menu in the editor toolbar
390 ///
391 /// Default: true
392 pub selections_menu: Option<bool>,
393}
394
395/// Scrollbar related settings
396#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
397pub struct ScrollbarContent {
398 /// When to show the scrollbar in the editor.
399 ///
400 /// Default: auto
401 pub show: Option<ShowScrollbar>,
402 /// Whether to show git diff indicators in the scrollbar.
403 ///
404 /// Default: true
405 pub git_diff: Option<bool>,
406 /// Whether to show buffer search result indicators in the scrollbar.
407 ///
408 /// Default: true
409 pub search_results: Option<bool>,
410 /// Whether to show selected text occurrences in the scrollbar.
411 ///
412 /// Default: true
413 pub selected_text: 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 breakpoints in the gutter.
460 ///
461 /// Default: true
462 pub breakpoints: Option<bool>,
463 /// Whether to show fold buttons in the gutter.
464 ///
465 /// Default: true
466 pub folds: Option<bool>,
467}
468
469impl EditorSettings {
470 pub fn jupyter_enabled(cx: &App) -> bool {
471 EditorSettings::get_global(cx).jupyter.enabled
472 }
473}
474
475impl Settings for EditorSettings {
476 const KEY: Option<&'static str> = None;
477
478 type FileContent = EditorSettingsContent;
479
480 fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> anyhow::Result<Self> {
481 sources.json_merge()
482 }
483}