1mod language;
2mod terminal;
3mod theme;
4pub use language::*;
5pub use terminal::*;
6pub use theme::*;
7
8use std::env;
9
10use collections::HashMap;
11use gpui::{App, SharedString};
12use release_channel::ReleaseChannel;
13use schemars::JsonSchema;
14use serde::{Deserialize, Serialize};
15
16use crate::ActiveSettingsProfileName;
17
18#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
19pub struct SettingsContent {
20 #[serde(flatten)]
21 pub project: ProjectSettingsContent,
22
23 #[serde(flatten)]
24 pub theme: ThemeSettingsContent,
25
26 /// Configuration of audio in Zed.
27 pub audio: Option<AudioSettingsContent>,
28 pub auto_update: Option<bool>,
29
30 // todo!() comments?!
31 pub base_keymap: Option<BaseKeymapContent>,
32
33 /// The list of custom Git hosting providers.
34 pub git_hosting_providers: Option<Vec<GitHostingProviderConfig>>,
35
36 /// Whether or not to enable Helix mode.
37 ///
38 /// Default: false
39 pub helix_mode: Option<bool>,
40 /// A map of log scopes to the desired log level.
41 /// Useful for filtering out noisy logs or enabling more verbose logging.
42 ///
43 /// Example: {"log": {"client": "warn"}}
44 pub log: Option<HashMap<String, String>>,
45
46 /// Configuration of the terminal in Zed.
47 pub terminal: Option<TerminalSettingsContent>,
48
49 pub title_bar: Option<TitleBarSettingsContent>,
50
51 /// Whether or not to enable Vim mode.
52 ///
53 /// Default: false
54 pub vim_mode: Option<bool>,
55}
56
57impl SettingsContent {
58 pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
59 &mut self.project.all_languages.languages.0
60 }
61}
62
63// todo!() what should this be?
64#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
65pub struct ServerSettingsContent {
66 #[serde(flatten)]
67 pub project: ProjectSettingsContent,
68}
69
70#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
71pub struct UserSettingsContent {
72 #[serde(flatten)]
73 pub content: SettingsContent,
74
75 pub dev: Option<SettingsContent>,
76 pub nightly: Option<SettingsContent>,
77 pub preview: Option<SettingsContent>,
78 pub stable: Option<SettingsContent>,
79
80 pub macos: Option<SettingsContent>,
81 pub windows: Option<SettingsContent>,
82 pub linux: Option<SettingsContent>,
83
84 #[serde(default)]
85 pub profiles: HashMap<String, SettingsContent>,
86}
87
88pub struct ExtensionsSettingsContent {
89 pub all_languages: AllLanguageSettingsContent,
90}
91
92impl UserSettingsContent {
93 pub fn for_release_channel(&self) -> Option<&SettingsContent> {
94 match *release_channel::RELEASE_CHANNEL {
95 ReleaseChannel::Dev => self.dev.as_ref(),
96 ReleaseChannel::Nightly => self.nightly.as_ref(),
97 ReleaseChannel::Preview => self.preview.as_ref(),
98 ReleaseChannel::Stable => self.stable.as_ref(),
99 }
100 }
101
102 pub fn for_os(&self) -> Option<&SettingsContent> {
103 match env::consts::OS {
104 "macos" => self.macos.as_ref(),
105 "linux" => self.linux.as_ref(),
106 "windows" => self.windows.as_ref(),
107 _ => None,
108 }
109 }
110
111 pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
112 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
113 return None;
114 };
115 self.profiles.get(&active_profile.0)
116 }
117}
118
119/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
120///
121/// Default: VSCode
122#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
123pub enum BaseKeymapContent {
124 #[default]
125 VSCode,
126 JetBrains,
127 SublimeText,
128 Atom,
129 TextMate,
130 Emacs,
131 Cursor,
132 None,
133}
134
135#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
136pub struct ProjectSettingsContent {
137 #[serde(flatten)]
138 pub all_languages: AllLanguageSettingsContent,
139
140 #[serde(flatten)]
141 pub worktree: WorktreeSettingsContent,
142}
143
144#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
145pub struct TitleBarSettingsContent {
146 /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
147 ///
148 /// Default: "always"
149 pub show: Option<TitleBarVisibilityContent>,
150 /// Whether to show the branch icon beside branch switcher in the title bar.
151 ///
152 /// Default: false
153 pub show_branch_icon: Option<bool>,
154 /// Whether to show onboarding banners in the title bar.
155 ///
156 /// Default: true
157 pub show_onboarding_banner: Option<bool>,
158 /// Whether to show user avatar in the title bar.
159 ///
160 /// Default: true
161 pub show_user_picture: Option<bool>,
162 /// Whether to show the branch name button in the titlebar.
163 ///
164 /// Default: true
165 pub show_branch_name: Option<bool>,
166 /// Whether to show the project host and name in the titlebar.
167 ///
168 /// Default: true
169 pub show_project_items: Option<bool>,
170 /// Whether to show the sign in button in the title bar.
171 ///
172 /// Default: true
173 pub show_sign_in: Option<bool>,
174 /// Whether to show the menus in the title bar.
175 ///
176 /// Default: false
177 pub show_menus: Option<bool>,
178}
179
180#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
181#[serde(rename_all = "snake_case")]
182pub enum TitleBarVisibilityContent {
183 Always,
184 Never,
185 HideInFullScreen,
186}
187
188/// Configuration of audio in Zed.
189#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
190pub struct AudioSettingsContent {
191 /// Opt into the new audio system.
192 #[serde(rename = "experimental.rodio_audio", default)]
193 pub rodio_audio: Option<bool>,
194 /// Requires 'rodio_audio: true'
195 ///
196 /// Use the new audio systems automatic gain control for your microphone.
197 /// This affects how loud you sound to others.
198 #[serde(rename = "experimental.control_input_volume", default)]
199 pub control_input_volume: Option<bool>,
200 /// Requires 'rodio_audio: true'
201 ///
202 /// Use the new audio systems automatic gain control on everyone in the
203 /// call. This makes call members who are too quite louder and those who are
204 /// too loud quieter. This only affects how things sound for you.
205 #[serde(rename = "experimental.control_output_volume", default)]
206 pub control_output_volume: Option<bool>,
207}
208
209/// A custom Git hosting provider.
210#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
211pub struct GitHostingProviderConfig {
212 /// The type of the provider.
213 ///
214 /// Must be one of `github`, `gitlab`, or `bitbucket`.
215 pub provider: GitHostingProviderKind,
216
217 /// The base URL for the provider (e.g., "https://code.corp.big.com").
218 pub base_url: String,
219
220 /// The display name for the provider (e.g., "BigCorp GitHub").
221 pub name: String,
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
225#[serde(rename_all = "snake_case")]
226pub enum GitHostingProviderKind {
227 Github,
228 Gitlab,
229 Bitbucket,
230}
231
232#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
233pub struct WorktreeSettingsContent {
234 /// The displayed name of this project. If not set, the root directory name
235 /// will be displayed.
236 ///
237 /// Default: none
238 pub project_name: Option<String>,
239
240 /// Completely ignore files matching globs from `file_scan_exclusions`. Overrides
241 /// `file_scan_inclusions`.
242 ///
243 /// Default: [
244 /// "**/.git",
245 /// "**/.svn",
246 /// "**/.hg",
247 /// "**/.jj",
248 /// "**/CVS",
249 /// "**/.DS_Store",
250 /// "**/Thumbs.db",
251 /// "**/.classpath",
252 /// "**/.settings"
253 /// ]
254 pub file_scan_exclusions: Option<Vec<String>>,
255
256 /// Always include files that match these globs when scanning for files, even if they're
257 /// ignored by git. This setting is overridden by `file_scan_exclusions`.
258 /// Default: [
259 /// ".env*",
260 /// "docker-compose.*.yml",
261 /// ]
262 pub file_scan_inclusions: Option<Vec<String>>,
263
264 /// Treat the files matching these globs as `.env` files.
265 /// Default: [ "**/.env*" ]
266 pub private_files: Option<Vec<String>>,
267}