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