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