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