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