settings_content.rs

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