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