1mod agent;
2mod language;
3mod project;
4mod terminal;
5mod theme;
6pub use agent::*;
7pub use language::*;
8pub use project::*;
9pub use terminal::*;
10pub use theme::*;
11
12use collections::HashMap;
13use gpui::{App, SharedString};
14use release_channel::ReleaseChannel;
15use schemars::JsonSchema;
16use serde::{Deserialize, Serialize};
17use std::env;
18pub use util::serde::default_true;
19
20use crate::ActiveSettingsProfileName;
21
22#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
23pub struct SettingsContent {
24 #[serde(flatten)]
25 pub project: ProjectSettingsContent,
26
27 #[serde(flatten)]
28 pub theme: ThemeSettingsContent,
29
30 pub agent: Option<AgentSettingsContent>,
31 pub agent_servers: Option<AllAgentServersSettings>,
32
33 /// Configuration of audio in Zed.
34 pub audio: Option<AudioSettingsContent>,
35 pub auto_update: Option<bool>,
36
37 // todo!() comments?!
38 pub base_keymap: Option<BaseKeymapContent>,
39
40 pub debugger: Option<DebuggerSettingsContent>,
41
42 /// Configuration for Diagnostics-related features.
43 pub diagnostics: Option<DiagnosticsSettingsContent>,
44
45 /// Configuration for Git-related features
46 pub git: Option<GitSettings>,
47
48 /// The list of custom Git hosting providers.
49 pub git_hosting_providers: Option<Vec<GitHostingProviderConfig>>,
50
51 /// Common language server settings.
52 pub global_lsp_settings: Option<GlobalLspSettingsContent>,
53
54 /// Whether or not to enable Helix mode.
55 ///
56 /// Default: false
57 pub helix_mode: Option<bool>,
58 /// A map of log scopes to the desired log level.
59 /// Useful for filtering out noisy logs or enabling more verbose logging.
60 ///
61 /// Example: {"log": {"client": "warn"}}
62 pub log: Option<HashMap<String, String>>,
63
64 /// Configuration for Node-related features
65 pub node: Option<NodeBinarySettings>,
66
67 pub proxy: Option<String>,
68
69 /// The URL of the Zed server to connect to.
70 pub server_url: Option<String>,
71
72 /// Configuration for session-related features
73 pub session: Option<SessionSettings>,
74 /// Control what info is collected by Zed.
75 pub telemetry: Option<TelemetrySettingsContent>,
76
77 /// Configuration of the terminal in Zed.
78 pub terminal: Option<TerminalSettingsContent>,
79
80 pub title_bar: Option<TitleBarSettingsContent>,
81
82 /// Whether or not to enable Vim mode.
83 ///
84 /// Default: false
85 pub vim_mode: Option<bool>,
86
87 // Settings related to calls in Zed
88 pub calls: Option<CallSettingsContent>,
89}
90
91impl SettingsContent {
92 pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
93 &mut self.project.all_languages.languages.0
94 }
95}
96
97// todo!() what should this be?
98#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
99pub struct ServerSettingsContent {
100 #[serde(flatten)]
101 pub project: ProjectSettingsContent,
102}
103
104#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
105pub struct UserSettingsContent {
106 #[serde(flatten)]
107 pub content: SettingsContent,
108
109 pub dev: Option<SettingsContent>,
110 pub nightly: Option<SettingsContent>,
111 pub preview: Option<SettingsContent>,
112 pub stable: Option<SettingsContent>,
113
114 pub macos: Option<SettingsContent>,
115 pub windows: Option<SettingsContent>,
116 pub linux: Option<SettingsContent>,
117
118 #[serde(default)]
119 pub profiles: HashMap<String, SettingsContent>,
120}
121
122pub struct ExtensionsSettingsContent {
123 pub all_languages: AllLanguageSettingsContent,
124}
125
126impl UserSettingsContent {
127 pub fn for_release_channel(&self) -> Option<&SettingsContent> {
128 match *release_channel::RELEASE_CHANNEL {
129 ReleaseChannel::Dev => self.dev.as_ref(),
130 ReleaseChannel::Nightly => self.nightly.as_ref(),
131 ReleaseChannel::Preview => self.preview.as_ref(),
132 ReleaseChannel::Stable => self.stable.as_ref(),
133 }
134 }
135
136 pub fn for_os(&self) -> Option<&SettingsContent> {
137 match env::consts::OS {
138 "macos" => self.macos.as_ref(),
139 "linux" => self.linux.as_ref(),
140 "windows" => self.windows.as_ref(),
141 _ => None,
142 }
143 }
144
145 pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
146 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
147 return None;
148 };
149 self.profiles.get(&active_profile.0)
150 }
151}
152
153/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
154///
155/// Default: VSCode
156#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
157pub enum BaseKeymapContent {
158 #[default]
159 VSCode,
160 JetBrains,
161 SublimeText,
162 Atom,
163 TextMate,
164 Emacs,
165 Cursor,
166 None,
167}
168
169#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
170pub struct TitleBarSettingsContent {
171 /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
172 ///
173 /// Default: "always"
174 pub show: Option<TitleBarVisibilityContent>,
175 /// Whether to show the branch icon beside branch switcher in the title bar.
176 ///
177 /// Default: false
178 pub show_branch_icon: Option<bool>,
179 /// Whether to show onboarding banners in the title bar.
180 ///
181 /// Default: true
182 pub show_onboarding_banner: Option<bool>,
183 /// Whether to show user avatar in the title bar.
184 ///
185 /// Default: true
186 pub show_user_picture: Option<bool>,
187 /// Whether to show the branch name button in the titlebar.
188 ///
189 /// Default: true
190 pub show_branch_name: Option<bool>,
191 /// Whether to show the project host and name in the titlebar.
192 ///
193 /// Default: true
194 pub show_project_items: Option<bool>,
195 /// Whether to show the sign in button in the title bar.
196 ///
197 /// Default: true
198 pub show_sign_in: Option<bool>,
199 /// Whether to show the menus in the title bar.
200 ///
201 /// Default: false
202 pub show_menus: Option<bool>,
203}
204
205#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
206#[serde(rename_all = "snake_case")]
207pub enum TitleBarVisibilityContent {
208 Always,
209 Never,
210 HideInFullScreen,
211}
212
213/// Configuration of audio in Zed.
214#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
215pub struct AudioSettingsContent {
216 /// Opt into the new audio system.
217 #[serde(rename = "experimental.rodio_audio", default)]
218 pub rodio_audio: Option<bool>,
219 /// Requires 'rodio_audio: true'
220 ///
221 /// Use the new audio systems automatic gain control for your microphone.
222 /// This affects how loud you sound to others.
223 #[serde(rename = "experimental.control_input_volume", default)]
224 pub control_input_volume: Option<bool>,
225 /// Requires 'rodio_audio: true'
226 ///
227 /// Use the new audio systems automatic gain control on everyone in the
228 /// call. This makes call members who are too quite louder and those who are
229 /// too loud quieter. This only affects how things sound for you.
230 #[serde(rename = "experimental.control_output_volume", default)]
231 pub control_output_volume: Option<bool>,
232}
233
234/// A custom Git hosting provider.
235#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
236pub struct GitHostingProviderConfig {
237 /// The type of the provider.
238 ///
239 /// Must be one of `github`, `gitlab`, or `bitbucket`.
240 pub provider: GitHostingProviderKind,
241
242 /// The base URL for the provider (e.g., "https://code.corp.big.com").
243 pub base_url: String,
244
245 /// The display name for the provider (e.g., "BigCorp GitHub").
246 pub name: String,
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
250#[serde(rename_all = "snake_case")]
251pub enum GitHostingProviderKind {
252 Github,
253 Gitlab,
254 Bitbucket,
255}
256
257/// Control what info is collected by Zed.
258#[derive(Default, Clone, Serialize, Deserialize, JsonSchema, Debug)]
259pub struct TelemetrySettingsContent {
260 /// Send debug info like crash reports.
261 ///
262 /// Default: true
263 pub diagnostics: Option<bool>,
264 /// Send anonymized usage data like what languages you're using Zed with.
265 ///
266 /// Default: true
267 pub metrics: Option<bool>,
268}
269
270#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
271pub struct DebuggerSettingsContent {
272 /// Determines the stepping granularity.
273 ///
274 /// Default: line
275 pub stepping_granularity: Option<SteppingGranularity>,
276 /// Whether the breakpoints should be reused across Zed sessions.
277 ///
278 /// Default: true
279 pub save_breakpoints: Option<bool>,
280 /// Whether to show the debug button in the status bar.
281 ///
282 /// Default: true
283 pub button: Option<bool>,
284 /// Time in milliseconds until timeout error when connecting to a TCP debug adapter
285 ///
286 /// Default: 2000ms
287 pub timeout: Option<u64>,
288 /// Whether to log messages between active debug adapters and Zed
289 ///
290 /// Default: true
291 pub log_dap_communications: Option<bool>,
292 /// Whether to format dap messages in when adding them to debug adapter logger
293 ///
294 /// Default: true
295 pub format_dap_log_messages: Option<bool>,
296 /// The dock position of the debug panel
297 ///
298 /// Default: Bottom
299 pub dock: Option<DockPosition>,
300}
301
302/// The granularity of one 'step' in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`.
303#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy, Deserialize, Serialize, JsonSchema)]
304#[serde(rename_all = "snake_case")]
305pub enum SteppingGranularity {
306 /// The step should allow the program to run until the current statement has finished executing.
307 /// The meaning of a statement is determined by the adapter and it may be considered equivalent to a line.
308 /// For example 'for(int i = 0; i < 10; i++)' could be considered to have 3 statements 'int i = 0', 'i < 10', and 'i++'.
309 Statement,
310 /// The step should allow the program to run until the current source line has executed.
311 Line,
312 /// The step should allow one instruction to execute (e.g. one x86 instruction).
313 Instruction,
314}
315
316#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
317#[serde(rename_all = "snake_case")]
318pub enum DockPosition {
319 Left,
320 Bottom,
321 Right,
322}
323
324/// Settings for slash commands.
325#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema)]
326pub struct SlashCommandSettings {
327 /// Settings for the `/cargo-workspace` slash command.
328 pub cargo_workspace: Option<CargoWorkspaceCommandSettings>,
329}
330
331/// Settings for the `/cargo-workspace` slash command.
332#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema)]
333pub struct CargoWorkspaceCommandSettings {
334 /// Whether `/cargo-workspace` is enabled.
335 pub enabled: Option<bool>,
336}
337
338/// Configuration of voice calls in Zed.
339#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
340pub struct CallSettingsContent {
341 /// Whether the microphone should be muted when joining a channel or a call.
342 ///
343 /// Default: false
344 pub mute_on_join: Option<bool>,
345
346 /// Whether your current project should be shared when joining an empty channel.
347 ///
348 /// Default: false
349 pub share_on_join: Option<bool>,
350}