settings_content.rs

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