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