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