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