settings_content.rs

  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
141#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
142pub struct TitleBarSettingsContent {
143    /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
144    ///
145    /// Default: "always"
146    pub show: Option<TitleBarVisibilityContent>,
147    /// Whether to show the branch icon beside branch switcher in the title bar.
148    ///
149    /// Default: false
150    pub show_branch_icon: Option<bool>,
151    /// Whether to show onboarding banners in the title bar.
152    ///
153    /// Default: true
154    pub show_onboarding_banner: Option<bool>,
155    /// Whether to show user avatar in the title bar.
156    ///
157    /// Default: true
158    pub show_user_picture: Option<bool>,
159    /// Whether to show the branch name button in the titlebar.
160    ///
161    /// Default: true
162    pub show_branch_name: Option<bool>,
163    /// Whether to show the project host and name in the titlebar.
164    ///
165    /// Default: true
166    pub show_project_items: Option<bool>,
167    /// Whether to show the sign in button in the title bar.
168    ///
169    /// Default: true
170    pub show_sign_in: Option<bool>,
171    /// Whether to show the menus in the title bar.
172    ///
173    /// Default: false
174    pub show_menus: Option<bool>,
175}
176
177#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
178#[serde(rename_all = "snake_case")]
179pub enum TitleBarVisibilityContent {
180    Always,
181    Never,
182    HideInFullScreen,
183}
184
185/// Configuration of audio in Zed.
186#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
187pub struct AudioSettingsContent {
188    /// Opt into the new audio system.
189    #[serde(rename = "experimental.rodio_audio", default)]
190    pub rodio_audio: Option<bool>,
191    /// Requires 'rodio_audio: true'
192    ///
193    /// Use the new audio systems automatic gain control for your microphone.
194    /// This affects how loud you sound to others.
195    #[serde(rename = "experimental.control_input_volume", default)]
196    pub control_input_volume: Option<bool>,
197    /// Requires 'rodio_audio: true'
198    ///
199    /// Use the new audio systems automatic gain control on everyone in the
200    /// call. This makes call members who are too quite louder and those who are
201    /// too loud quieter. This only affects how things sound for you.
202    #[serde(rename = "experimental.control_output_volume", default)]
203    pub control_output_volume: Option<bool>,
204}
205
206/// A custom Git hosting provider.
207#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
208pub struct GitHostingProviderConfig {
209    /// The type of the provider.
210    ///
211    /// Must be one of `github`, `gitlab`, or `bitbucket`.
212    pub provider: GitHostingProviderKind,
213
214    /// The base URL for the provider (e.g., "https://code.corp.big.com").
215    pub base_url: String,
216
217    /// The display name for the provider (e.g., "BigCorp GitHub").
218    pub name: String,
219}
220
221#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
222#[serde(rename_all = "snake_case")]
223pub enum GitHostingProviderKind {
224    Github,
225    Gitlab,
226    Bitbucket,
227}