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