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