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
44impl SettingsContent {
45 pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
46 &mut self.project.all_languages.languages.0
47 }
48}
49
50// todo!() what should this be?
51#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
52pub struct ServerSettingsContent {
53 #[serde(flatten)]
54 pub project: ProjectSettingsContent,
55}
56
57#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
58pub struct UserSettingsContent {
59 #[serde(flatten)]
60 pub content: SettingsContent,
61
62 pub dev: Option<SettingsContent>,
63 pub nightly: Option<SettingsContent>,
64 pub preview: Option<SettingsContent>,
65 pub stable: Option<SettingsContent>,
66
67 pub macos: Option<SettingsContent>,
68 pub windows: Option<SettingsContent>,
69 pub linux: Option<SettingsContent>,
70
71 #[serde(default)]
72 pub profiles: HashMap<String, SettingsContent>,
73}
74
75pub struct ExtensionsSettingsContent {
76 pub all_languages: AllLanguageSettingsContent,
77}
78
79impl UserSettingsContent {
80 pub fn for_release_channel(&self) -> Option<&SettingsContent> {
81 match *release_channel::RELEASE_CHANNEL {
82 ReleaseChannel::Dev => self.dev.as_ref(),
83 ReleaseChannel::Nightly => self.nightly.as_ref(),
84 ReleaseChannel::Preview => self.preview.as_ref(),
85 ReleaseChannel::Stable => self.stable.as_ref(),
86 }
87 }
88
89 pub fn for_os(&self) -> Option<&SettingsContent> {
90 match env::consts::OS {
91 "macos" => self.macos.as_ref(),
92 "linux" => self.linux.as_ref(),
93 "windows" => self.windows.as_ref(),
94 _ => None,
95 }
96 }
97
98 pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
99 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
100 return None;
101 };
102 self.profiles.get(&active_profile.0)
103 }
104}
105
106/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
107///
108/// Default: VSCode
109#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
110pub enum BaseKeymapContent {
111 #[default]
112 VSCode,
113 JetBrains,
114 SublimeText,
115 Atom,
116 TextMate,
117 Emacs,
118 Cursor,
119 None,
120}
121
122#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
123pub struct ProjectSettingsContent {
124 #[serde(flatten)]
125 pub(crate) all_languages: AllLanguageSettingsContent,
126}
127
128#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
129pub struct TitleBarSettingsContent {
130 /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
131 ///
132 /// Default: "always"
133 pub show: Option<TitleBarVisibilityContent>,
134 /// Whether to show the branch icon beside branch switcher in the title bar.
135 ///
136 /// Default: false
137 pub show_branch_icon: Option<bool>,
138 /// Whether to show onboarding banners in the title bar.
139 ///
140 /// Default: true
141 pub show_onboarding_banner: Option<bool>,
142 /// Whether to show user avatar in the title bar.
143 ///
144 /// Default: true
145 pub show_user_picture: Option<bool>,
146 /// Whether to show the branch name button in the titlebar.
147 ///
148 /// Default: true
149 pub show_branch_name: Option<bool>,
150 /// Whether to show the project host and name in the titlebar.
151 ///
152 /// Default: true
153 pub show_project_items: Option<bool>,
154 /// Whether to show the sign in button in the title bar.
155 ///
156 /// Default: true
157 pub show_sign_in: Option<bool>,
158 /// Whether to show the menus in the title bar.
159 ///
160 /// Default: false
161 pub show_menus: Option<bool>,
162}
163
164#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
165#[serde(rename_all = "snake_case")]
166pub enum TitleBarVisibilityContent {
167 Always,
168 Never,
169 HideInFullScreen,
170}
171
172/// Configuration of audio in Zed.
173#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
174pub struct AudioSettingsContent {
175 /// Opt into the new audio system.
176 #[serde(rename = "experimental.rodio_audio", default)]
177 pub rodio_audio: Option<bool>,
178 /// Requires 'rodio_audio: true'
179 ///
180 /// Use the new audio systems automatic gain control for your microphone.
181 /// This affects how loud you sound to others.
182 #[serde(rename = "experimental.control_input_volume", default)]
183 pub control_input_volume: Option<bool>,
184 /// Requires 'rodio_audio: true'
185 ///
186 /// Use the new audio systems automatic gain control on everyone in the
187 /// call. This makes call members who are too quite louder and those who are
188 /// too loud quieter. This only affects how things sound for you.
189 #[serde(rename = "experimental.control_output_volume", default)]
190 pub control_output_volume: Option<bool>,
191}