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