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