1use gpui::AppContext;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use settings::{Settings, SettingsSources};
5
6#[derive(Deserialize, Clone)]
7pub struct EditorSettings {
8 pub cursor_blink: bool,
9 pub current_line_highlight: CurrentLineHighlight,
10 pub hover_popover_enabled: bool,
11 pub show_completions_on_input: bool,
12 pub show_completion_documentation: bool,
13 pub completion_documentation_secondary_query_debounce: u64,
14 pub use_on_type_format: bool,
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 scroll_sensitivity: f32,
21 pub relative_line_numbers: bool,
22 pub seed_search_query_from_cursor: SeedQuerySetting,
23 pub use_smartcase_search: bool,
24 pub multi_cursor_modifier: MultiCursorModifier,
25 pub redact_private_values: bool,
26 pub expand_excerpt_lines: u32,
27 pub middle_click_paste: bool,
28 #[serde(default)]
29 pub double_click_in_multibuffer: DoubleClickInMultibuffer,
30 pub search_wrap: bool,
31 #[serde(default)]
32 pub search: SearchSettings,
33 pub auto_signature_help: bool,
34 pub show_signature_help_after_edits: bool,
35 pub jupyter: Jupyter,
36}
37
38#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
39#[serde(rename_all = "snake_case")]
40pub enum CurrentLineHighlight {
41 // Don't highlight the current line.
42 None,
43 // Highlight the gutter area.
44 Gutter,
45 // Highlight the editor area.
46 Line,
47 // Highlight the full line.
48 All,
49}
50
51/// When to populate a new search's query based on the text under the cursor.
52#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
53#[serde(rename_all = "snake_case")]
54pub enum SeedQuerySetting {
55 /// Always populate the search query with the word under the cursor.
56 Always,
57 /// Only populate the search query when there is text selected.
58 Selection,
59 /// Never populate the search query
60 Never,
61}
62
63/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
64#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
65#[serde(rename_all = "snake_case")]
66pub enum DoubleClickInMultibuffer {
67 /// Behave as a regular buffer and select the whole word.
68 #[default]
69 Select,
70 /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
71 /// Otherwise, behave as a regular buffer and select the whole word.
72 Open,
73}
74
75#[derive(Debug, Clone, Deserialize)]
76pub struct Jupyter {
77 /// Whether the Jupyter feature is enabled.
78 ///
79 /// Default: true
80 pub enabled: bool,
81}
82
83#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
84#[serde(rename_all = "snake_case")]
85pub struct JupyterContent {
86 /// Whether the Jupyter feature is enabled.
87 ///
88 /// Default: true
89 pub enabled: Option<bool>,
90}
91
92#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
93pub struct Toolbar {
94 pub breadcrumbs: bool,
95 pub quick_actions: bool,
96 pub selections_menu: bool,
97}
98
99#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
100pub struct Scrollbar {
101 pub show: ShowScrollbar,
102 pub git_diff: bool,
103 pub selected_symbol: bool,
104 pub search_results: bool,
105 pub diagnostics: bool,
106 pub cursors: bool,
107}
108
109#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
110pub struct Gutter {
111 pub line_numbers: bool,
112 pub code_actions: bool,
113 pub runnables: bool,
114 pub folds: bool,
115}
116
117/// When to show the scrollbar in the editor.
118///
119/// Default: auto
120#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
121#[serde(rename_all = "snake_case")]
122pub enum ShowScrollbar {
123 /// Show the scrollbar if there's important information or
124 /// follow the system's configured behavior.
125 Auto,
126 /// Match the system's configured behavior.
127 System,
128 /// Always show the scrollbar.
129 Always,
130 /// Never show the scrollbar.
131 Never,
132}
133
134/// The key to use for adding multiple cursors
135///
136/// Default: alt
137#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
138#[serde(rename_all = "snake_case")]
139pub enum MultiCursorModifier {
140 Alt,
141 #[serde(alias = "cmd", alias = "ctrl")]
142 CmdOrCtrl,
143}
144
145/// Whether the editor will scroll beyond the last line.
146///
147/// Default: one_page
148#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
149#[serde(rename_all = "snake_case")]
150pub enum ScrollBeyondLastLine {
151 /// The editor will not scroll beyond the last line.
152 Off,
153
154 /// The editor will scroll beyond the last line by one page.
155 OnePage,
156
157 /// The editor will scroll beyond the last line by the same number of lines as vertical_scroll_margin.
158 VerticalScrollMargin,
159}
160
161/// Default options for buffer and project search items.
162#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
163pub struct SearchSettings {
164 #[serde(default)]
165 pub whole_word: bool,
166 #[serde(default)]
167 pub case_sensitive: bool,
168 #[serde(default)]
169 pub include_ignored: bool,
170 #[serde(default)]
171 pub regex: bool,
172}
173
174#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
175pub struct EditorSettingsContent {
176 /// Whether the cursor blinks in the editor.
177 ///
178 /// Default: true
179 pub cursor_blink: Option<bool>,
180 /// How to highlight the current line in the editor.
181 ///
182 /// Default: all
183 pub current_line_highlight: Option<CurrentLineHighlight>,
184 /// Whether to show the informational hover box when moving the mouse
185 /// over symbols in the editor.
186 ///
187 /// Default: true
188 pub hover_popover_enabled: Option<bool>,
189
190 /// Whether to pop the completions menu while typing in an editor without
191 /// explicitly requesting it.
192 ///
193 /// Default: true
194 pub show_completions_on_input: Option<bool>,
195 /// Whether to display inline and alongside documentation for items in the
196 /// completions menu.
197 ///
198 /// Default: true
199 pub show_completion_documentation: Option<bool>,
200 /// The debounce delay before re-querying the language server for completion
201 /// documentation when not included in original completion list.
202 ///
203 /// Default: 300 ms
204 pub completion_documentation_secondary_query_debounce: Option<u64>,
205 /// Whether to use additional LSP queries to format (and amend) the code after
206 /// every "trigger" symbol input, defined by LSP server capabilities.
207 ///
208 /// Default: true
209 pub use_on_type_format: Option<bool>,
210 /// Toolbar related settings
211 pub toolbar: Option<ToolbarContent>,
212 /// Scrollbar related settings
213 pub scrollbar: Option<ScrollbarContent>,
214 /// Gutter related settings
215 pub gutter: Option<GutterContent>,
216 /// Whether the editor will scroll beyond the last line.
217 ///
218 /// Default: one_page
219 pub scroll_beyond_last_line: Option<ScrollBeyondLastLine>,
220 /// The number of lines to keep above/below the cursor when auto-scrolling.
221 ///
222 /// Default: 3.
223 pub vertical_scroll_margin: Option<f32>,
224 /// Scroll sensitivity multiplier. This multiplier is applied
225 /// to both the horizontal and vertical delta values while scrolling.
226 ///
227 /// Default: 1.0
228 pub scroll_sensitivity: Option<f32>,
229 /// Whether the line numbers on editors gutter are relative or not.
230 ///
231 /// Default: false
232 pub relative_line_numbers: Option<bool>,
233 /// When to populate a new search's query based on the text under the cursor.
234 ///
235 /// Default: always
236 pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
237 pub use_smartcase_search: Option<bool>,
238 /// The key to use for adding multiple cursors
239 ///
240 /// Default: alt
241 pub multi_cursor_modifier: Option<MultiCursorModifier>,
242 /// Hide the values of variables in `private` files, as defined by the
243 /// private_files setting. This only changes the visual representation,
244 /// the values are still present in the file and can be selected / copied / pasted
245 ///
246 /// Default: false
247 pub redact_private_values: Option<bool>,
248
249 /// How many lines to expand the multibuffer excerpts by default
250 ///
251 /// Default: 3
252 pub expand_excerpt_lines: Option<u32>,
253
254 /// Whether to enable middle-click paste on Linux
255 ///
256 /// Default: true
257 pub middle_click_paste: Option<bool>,
258
259 /// What to do when multibuffer is double clicked in some of its excerpts
260 /// (parts of singleton buffers).
261 ///
262 /// Default: select
263 pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
264 /// Whether the editor search results will loop
265 ///
266 /// Default: true
267 pub search_wrap: Option<bool>,
268
269 /// Defaults to use when opening a new buffer and project search items.
270 ///
271 /// Default: nothing is enabled
272 pub search: Option<SearchSettings>,
273
274 /// Whether to automatically show a signature help pop-up or not.
275 ///
276 /// Default: false
277 pub auto_signature_help: Option<bool>,
278
279 /// Whether to show the signature help pop-up after completions or bracket pairs inserted.
280 ///
281 /// Default: true
282 pub show_signature_help_after_edits: Option<bool>,
283
284 /// Jupyter REPL settings.
285 pub jupyter: Option<JupyterContent>,
286}
287
288// Toolbar related settings
289#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
290pub struct ToolbarContent {
291 /// Whether to display breadcrumbs in the editor toolbar.
292 ///
293 /// Default: true
294 pub breadcrumbs: Option<bool>,
295 /// Whether to display quick action buttons in the editor toolbar.
296 ///
297 /// Default: true
298 pub quick_actions: Option<bool>,
299
300 /// Whether to show the selections menu in the editor toolbar
301 ///
302 /// Default: true
303 pub selections_menu: Option<bool>,
304}
305
306/// Scrollbar related settings
307#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
308pub struct ScrollbarContent {
309 /// When to show the scrollbar in the editor.
310 ///
311 /// Default: auto
312 pub show: Option<ShowScrollbar>,
313 /// Whether to show git diff indicators in the scrollbar.
314 ///
315 /// Default: true
316 pub git_diff: Option<bool>,
317 /// Whether to show buffer search result indicators in the scrollbar.
318 ///
319 /// Default: true
320 pub search_results: Option<bool>,
321 /// Whether to show selected symbol occurrences in the scrollbar.
322 ///
323 /// Default: true
324 pub selected_symbol: Option<bool>,
325 /// Whether to show diagnostic indicators in the scrollbar.
326 ///
327 /// Default: true
328 pub diagnostics: Option<bool>,
329 /// Whether to show cursor positions in the scrollbar.
330 ///
331 /// Default: true
332 pub cursors: Option<bool>,
333}
334
335/// Gutter related settings
336#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
337pub struct GutterContent {
338 /// Whether to show line numbers in the gutter.
339 ///
340 /// Default: true
341 pub line_numbers: Option<bool>,
342 /// Whether to show code action buttons in the gutter.
343 ///
344 /// Default: true
345 pub code_actions: Option<bool>,
346 /// Whether to show runnable buttons in the gutter.
347 ///
348 /// Default: true
349 pub runnables: Option<bool>,
350 /// Whether to show fold buttons in the gutter.
351 ///
352 /// Default: true
353 pub folds: Option<bool>,
354}
355
356impl EditorSettings {
357 pub fn jupyter_enabled(cx: &AppContext) -> bool {
358 EditorSettings::get_global(cx).jupyter.enabled
359 }
360}
361
362impl Settings for EditorSettings {
363 const KEY: Option<&'static str> = None;
364
365 type FileContent = EditorSettingsContent;
366
367 fn load(
368 sources: SettingsSources<Self::FileContent>,
369 _: &mut AppContext,
370 ) -> anyhow::Result<Self> {
371 sources.json_merge()
372 }
373}