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