1use gpui::AppContext;
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_inline_completions_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: bool,
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/// The key to use for adding multiple cursors
154///
155/// Default: alt
156#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
157#[serde(rename_all = "snake_case")]
158pub enum MultiCursorModifier {
159 Alt,
160 #[serde(alias = "cmd", alias = "ctrl")]
161 CmdOrCtrl,
162}
163
164/// Whether the editor will scroll beyond the last line.
165///
166/// Default: one_page
167#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
168#[serde(rename_all = "snake_case")]
169pub enum ScrollBeyondLastLine {
170 /// The editor will not scroll beyond the last line.
171 Off,
172
173 /// The editor will scroll beyond the last line by one page.
174 OnePage,
175
176 /// The editor will scroll beyond the last line by the same number of lines as vertical_scroll_margin.
177 VerticalScrollMargin,
178}
179
180/// Default options for buffer and project search items.
181#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
182pub struct SearchSettings {
183 #[serde(default)]
184 pub whole_word: bool,
185 #[serde(default)]
186 pub case_sensitive: bool,
187 #[serde(default)]
188 pub include_ignored: bool,
189 #[serde(default)]
190 pub regex: bool,
191}
192
193#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
194pub struct EditorSettingsContent {
195 /// Whether the cursor blinks in the editor.
196 ///
197 /// Default: true
198 pub cursor_blink: Option<bool>,
199 /// Cursor shape for the default editor.
200 /// Can be "bar", "block", "underline", or "hollow".
201 ///
202 /// Default: None
203 pub cursor_shape: Option<CursorShape>,
204 /// How to highlight the current line in the editor.
205 ///
206 /// Default: all
207 pub current_line_highlight: Option<CurrentLineHighlight>,
208 /// The debounce delay before querying highlights from the language
209 /// server based on the current cursor location.
210 ///
211 /// Default: 75
212 pub lsp_highlight_debounce: Option<u64>,
213 /// Whether to show the informational hover box when moving the mouse
214 /// over symbols in the editor.
215 ///
216 /// Default: true
217 pub hover_popover_enabled: Option<bool>,
218 /// Time to wait before showing the informational hover box
219 ///
220 /// Default: 350
221 pub hover_popover_delay: Option<u64>,
222 /// Toolbar related settings
223 pub toolbar: Option<ToolbarContent>,
224 /// Scrollbar related settings
225 pub scrollbar: Option<ScrollbarContent>,
226 /// Gutter related settings
227 pub gutter: Option<GutterContent>,
228 /// Whether the editor will scroll beyond the last line.
229 ///
230 /// Default: one_page
231 pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
232 /// The number of lines to keep above/below the cursor when auto-scrolling.
233 ///
234 /// Default: 3.
235 pub vertical_scroll_margin: Option<f32>,
236 /// Whether to scroll when clicking near the edge of the visible text area.
237 ///
238 /// Default: false
239 pub autoscroll_on_clicks: Option<bool>,
240 /// The number of characters to keep on either side when scrolling with the mouse.
241 ///
242 /// Default: 5.
243 pub horizontal_scroll_margin: Option<f32>,
244 /// Scroll sensitivity multiplier. This multiplier is applied
245 /// to both the horizontal and vertical delta values while scrolling.
246 ///
247 /// Default: 1.0
248 pub scroll_sensitivity: Option<f32>,
249 /// Whether the line numbers on editors gutter are relative or not.
250 ///
251 /// Default: false
252 pub relative_line_numbers: Option<bool>,
253 /// When to populate a new search's query based on the text under the cursor.
254 ///
255 /// Default: always
256 pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
257 pub use_smartcase_search: Option<bool>,
258 /// The key to use for adding multiple cursors
259 ///
260 /// Default: alt
261 pub multi_cursor_modifier: Option<MultiCursorModifier>,
262 /// Hide the values of variables in `private` files, as defined by the
263 /// private_files setting. This only changes the visual representation,
264 /// the values are still present in the file and can be selected / copied / pasted
265 ///
266 /// Default: false
267 pub redact_private_values: Option<bool>,
268
269 /// How many lines to expand the multibuffer excerpts by default
270 ///
271 /// Default: 3
272 pub expand_excerpt_lines: Option<u32>,
273
274 /// Whether to enable middle-click paste on Linux
275 ///
276 /// Default: true
277 pub middle_click_paste: Option<bool>,
278
279 /// What to do when multibuffer is double clicked in some of its excerpts
280 /// (parts of singleton buffers).
281 ///
282 /// Default: select
283 pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
284 /// Whether the editor search results will loop
285 ///
286 /// Default: true
287 pub search_wrap: Option<bool>,
288
289 /// Defaults to use when opening a new buffer and project search items.
290 ///
291 /// Default: nothing is enabled
292 pub search: Option<SearchSettings>,
293
294 /// Whether to automatically show a signature help pop-up or not.
295 ///
296 /// Default: false
297 pub auto_signature_help: Option<bool>,
298
299 /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
300 ///
301 /// Default: false
302 pub show_signature_help_after_edits: Option<bool>,
303
304 /// Whether to show the inline completions next to the completions provided by a language server.
305 /// Only has an effect if inline completion provider supports it.
306 ///
307 /// Default: true
308 pub show_inline_completions_in_menu: Option<bool>,
309
310 /// Jupyter REPL settings.
311 pub jupyter: Option<JupyterContent>,
312}
313
314// Toolbar related settings
315#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
316pub struct ToolbarContent {
317 /// Whether to display breadcrumbs in the editor toolbar.
318 ///
319 /// Default: true
320 pub breadcrumbs: Option<bool>,
321 /// Whether to display quick action buttons in the editor toolbar.
322 ///
323 /// Default: true
324 pub quick_actions: Option<bool>,
325
326 /// Whether to show the selections menu in the editor toolbar
327 ///
328 /// Default: true
329 pub selections_menu: Option<bool>,
330}
331
332/// Scrollbar related settings
333#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
334pub struct ScrollbarContent {
335 /// When to show the scrollbar in the editor.
336 ///
337 /// Default: auto
338 pub show: Option<ShowScrollbar>,
339 /// Whether to show git diff indicators in the scrollbar.
340 ///
341 /// Default: true
342 pub git_diff: Option<bool>,
343 /// Whether to show buffer search result indicators in the scrollbar.
344 ///
345 /// Default: true
346 pub search_results: Option<bool>,
347 /// Whether to show selected symbol occurrences in the scrollbar.
348 ///
349 /// Default: true
350 pub selected_symbol: Option<bool>,
351 /// Whether to show diagnostic indicators in the scrollbar.
352 ///
353 /// Default: true
354 pub diagnostics: Option<bool>,
355 /// Whether to show cursor positions in the scrollbar.
356 ///
357 /// Default: true
358 pub cursors: Option<bool>,
359 /// Forcefully enable or disable the scrollbar for each axis
360 pub axes: Option<ScrollbarAxesContent>,
361}
362
363/// Forcefully enable or disable the scrollbar for each axis
364#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
365pub struct ScrollbarAxesContent {
366 /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
367 ///
368 /// Default: true
369 horizontal: Option<bool>,
370
371 /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
372 ///
373 /// Default: true
374 vertical: Option<bool>,
375}
376
377/// Gutter related settings
378#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
379pub struct GutterContent {
380 /// Whether to show line numbers in the gutter.
381 ///
382 /// Default: true
383 pub line_numbers: Option<bool>,
384 /// Whether to show code action buttons in the gutter.
385 ///
386 /// Default: true
387 pub code_actions: Option<bool>,
388 /// Whether to show runnable buttons in the gutter.
389 ///
390 /// Default: true
391 pub runnables: Option<bool>,
392 /// Whether to show fold buttons in the gutter.
393 ///
394 /// Default: true
395 pub folds: Option<bool>,
396}
397
398impl EditorSettings {
399 pub fn jupyter_enabled(cx: &AppContext) -> bool {
400 EditorSettings::get_global(cx).jupyter.enabled
401 }
402}
403
404impl Settings for EditorSettings {
405 const KEY: Option<&'static str> = None;
406
407 type FileContent = EditorSettingsContent;
408
409 fn load(
410 sources: SettingsSources<Self::FileContent>,
411 _: &mut AppContext,
412 ) -> anyhow::Result<Self> {
413 sources.json_merge()
414 }
415}