1mod language;
2mod theme;
3pub use language::*;
4pub use theme::*;
5
6use std::env;
7
8use collections::HashMap;
9use gpui::{App, SharedString};
10use release_channel::ReleaseChannel;
11use schemars::JsonSchema;
12use serde::{Deserialize, Serialize};
13
14use crate::ActiveSettingsProfileName;
15
16#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
17pub struct SettingsContent {
18 #[serde(flatten)]
19 pub project: ProjectSettingsContent,
20
21 #[serde(flatten)]
22 pub theme: ThemeSettingsContent,
23
24 // todo!() comments?!
25 pub base_keymap: Option<BaseKeymapContent>,
26
27 pub auto_update: Option<bool>,
28
29 pub title_bar: Option<TitleBarSettingsContent>,
30
31 /// Whether or not to enable Vim mode.
32 ///
33 /// Default: false
34 pub vim_mode: Option<bool>,
35 /// Whether or not to enable Helix mode.
36 ///
37 /// Default: false
38 pub helix_mode: Option<bool>,
39
40 /// Configuration of audio in Zed.
41 pub audio: Option<AudioSettingsContent>,
42
43 /// A map of log scopes to the desired log level.
44 /// Useful for filtering out noisy logs or enabling more verbose logging.
45 ///
46 /// Example: {"log": {"client": "warn"}}
47 pub log: Option<HashMap<String, String>>,
48}
49
50impl SettingsContent {
51 pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
52 &mut self.project.all_languages.languages.0
53 }
54}
55
56// todo!() what should this be?
57#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
58pub struct ServerSettingsContent {
59 #[serde(flatten)]
60 pub project: ProjectSettingsContent,
61}
62
63#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
64pub struct UserSettingsContent {
65 #[serde(flatten)]
66 pub content: SettingsContent,
67
68 pub dev: Option<SettingsContent>,
69 pub nightly: Option<SettingsContent>,
70 pub preview: Option<SettingsContent>,
71 pub stable: Option<SettingsContent>,
72
73 pub macos: Option<SettingsContent>,
74 pub windows: Option<SettingsContent>,
75 pub linux: Option<SettingsContent>,
76
77 #[serde(default)]
78 pub profiles: HashMap<String, SettingsContent>,
79}
80
81pub struct ExtensionsSettingsContent {
82 pub all_languages: AllLanguageSettingsContent,
83}
84
85impl UserSettingsContent {
86 pub fn for_release_channel(&self) -> Option<&SettingsContent> {
87 match *release_channel::RELEASE_CHANNEL {
88 ReleaseChannel::Dev => self.dev.as_ref(),
89 ReleaseChannel::Nightly => self.nightly.as_ref(),
90 ReleaseChannel::Preview => self.preview.as_ref(),
91 ReleaseChannel::Stable => self.stable.as_ref(),
92 }
93 }
94
95 pub fn for_os(&self) -> Option<&SettingsContent> {
96 match env::consts::OS {
97 "macos" => self.macos.as_ref(),
98 "linux" => self.linux.as_ref(),
99 "windows" => self.windows.as_ref(),
100 _ => None,
101 }
102 }
103
104 pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
105 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
106 return None;
107 };
108 self.profiles.get(&active_profile.0)
109 }
110}
111
112/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
113///
114/// Default: VSCode
115#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
116pub enum BaseKeymapContent {
117 #[default]
118 VSCode,
119 JetBrains,
120 SublimeText,
121 Atom,
122 TextMate,
123 Emacs,
124 Cursor,
125 None,
126}
127
128#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
129pub struct ProjectSettingsContent {
130 #[serde(flatten)]
131 pub(crate) all_languages: AllLanguageSettingsContent,
132}
133
134#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
135pub struct TitleBarSettingsContent {
136 /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
137 ///
138 /// Default: "always"
139 pub show: Option<TitleBarVisibilityContent>,
140 /// Whether to show the branch icon beside branch switcher in the title bar.
141 ///
142 /// Default: false
143 pub show_branch_icon: Option<bool>,
144 /// Whether to show onboarding banners in the title bar.
145 ///
146 /// Default: true
147 pub show_onboarding_banner: Option<bool>,
148 /// Whether to show user avatar in the title bar.
149 ///
150 /// Default: true
151 pub show_user_picture: Option<bool>,
152 /// Whether to show the branch name button in the titlebar.
153 ///
154 /// Default: true
155 pub show_branch_name: Option<bool>,
156 /// Whether to show the project host and name in the titlebar.
157 ///
158 /// Default: true
159 pub show_project_items: Option<bool>,
160 /// Whether to show the sign in button in the title bar.
161 ///
162 /// Default: true
163 pub show_sign_in: Option<bool>,
164 /// Whether to show the menus in the title bar.
165 ///
166 /// Default: false
167 pub show_menus: Option<bool>,
168}
169
170#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
171#[serde(rename_all = "snake_case")]
172pub enum TitleBarVisibilityContent {
173 Always,
174 Never,
175 HideInFullScreen,
176}
177
178/// Configuration of audio in Zed.
179#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
180pub struct AudioSettingsContent {
181 /// Opt into the new audio system.
182 #[serde(rename = "experimental.rodio_audio", default)]
183 pub rodio_audio: Option<bool>,
184 /// Requires 'rodio_audio: true'
185 ///
186 /// Use the new audio systems automatic gain control for your microphone.
187 /// This affects how loud you sound to others.
188 #[serde(rename = "experimental.control_input_volume", default)]
189 pub control_input_volume: Option<bool>,
190 /// Requires 'rodio_audio: true'
191 ///
192 /// Use the new audio systems automatic gain control on everyone in the
193 /// call. This makes call members who are too quite louder and those who are
194 /// too loud quieter. This only affects how things sound for you.
195 #[serde(rename = "experimental.control_output_volume", default)]
196 pub control_output_volume: Option<bool>,
197}