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