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