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