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    pub agent_servers: Option<AllAgentServersSettings>,
 30
 31    /// Configuration of audio in Zed.
 32    pub audio: Option<AudioSettingsContent>,
 33    pub auto_update: Option<bool>,
 34
 35    // todo!() comments?!
 36    pub base_keymap: Option<BaseKeymapContent>,
 37
 38    pub debugger: Option<DebuggerSettingsContent>,
 39
 40    /// The list of custom Git hosting providers.
 41    pub git_hosting_providers: Option<Vec<GitHostingProviderConfig>>,
 42
 43    /// Whether or not to enable Helix mode.
 44    ///
 45    /// Default: false
 46    pub helix_mode: Option<bool>,
 47    /// A map of log scopes to the desired log level.
 48    /// Useful for filtering out noisy logs or enabling more verbose logging.
 49    ///
 50    /// Example: {"log": {"client": "warn"}}
 51    pub log: Option<HashMap<String, String>>,
 52
 53    pub proxy: Option<String>,
 54
 55    /// The URL of the Zed server to connect to.
 56    pub server_url: Option<String>,
 57
 58    /// Control what info is collected by Zed.
 59    pub telemetry: Option<TelemetrySettingsContent>,
 60
 61    /// Configuration of the terminal in Zed.
 62    pub terminal: Option<TerminalSettingsContent>,
 63
 64    pub title_bar: Option<TitleBarSettingsContent>,
 65
 66    /// Whether or not to enable Vim mode.
 67    ///
 68    /// Default: false
 69    pub vim_mode: Option<bool>,
 70}
 71
 72impl SettingsContent {
 73    pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
 74        &mut self.project.all_languages.languages.0
 75    }
 76}
 77
 78// todo!() what should this be?
 79#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
 80pub struct ServerSettingsContent {
 81    #[serde(flatten)]
 82    pub project: ProjectSettingsContent,
 83}
 84
 85#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
 86pub struct UserSettingsContent {
 87    #[serde(flatten)]
 88    pub content: SettingsContent,
 89
 90    pub dev: Option<SettingsContent>,
 91    pub nightly: Option<SettingsContent>,
 92    pub preview: Option<SettingsContent>,
 93    pub stable: Option<SettingsContent>,
 94
 95    pub macos: Option<SettingsContent>,
 96    pub windows: Option<SettingsContent>,
 97    pub linux: Option<SettingsContent>,
 98
 99    #[serde(default)]
100    pub profiles: HashMap<String, SettingsContent>,
101}
102
103pub struct ExtensionsSettingsContent {
104    pub all_languages: AllLanguageSettingsContent,
105}
106
107impl UserSettingsContent {
108    pub fn for_release_channel(&self) -> Option<&SettingsContent> {
109        match *release_channel::RELEASE_CHANNEL {
110            ReleaseChannel::Dev => self.dev.as_ref(),
111            ReleaseChannel::Nightly => self.nightly.as_ref(),
112            ReleaseChannel::Preview => self.preview.as_ref(),
113            ReleaseChannel::Stable => self.stable.as_ref(),
114        }
115    }
116
117    pub fn for_os(&self) -> Option<&SettingsContent> {
118        match env::consts::OS {
119            "macos" => self.macos.as_ref(),
120            "linux" => self.linux.as_ref(),
121            "windows" => self.windows.as_ref(),
122            _ => None,
123        }
124    }
125
126    pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
127        let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
128            return None;
129        };
130        self.profiles.get(&active_profile.0)
131    }
132}
133
134/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
135///
136/// Default: VSCode
137#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
138pub enum BaseKeymapContent {
139    #[default]
140    VSCode,
141    JetBrains,
142    SublimeText,
143    Atom,
144    TextMate,
145    Emacs,
146    Cursor,
147    None,
148}
149
150#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
151pub struct ProjectSettingsContent {
152    #[serde(flatten)]
153    pub all_languages: AllLanguageSettingsContent,
154
155    #[serde(flatten)]
156    pub worktree: WorktreeSettingsContent,
157}
158
159#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
160pub struct TitleBarSettingsContent {
161    /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
162    ///
163    /// Default: "always"
164    pub show: Option<TitleBarVisibilityContent>,
165    /// Whether to show the branch icon beside branch switcher in the title bar.
166    ///
167    /// Default: false
168    pub show_branch_icon: Option<bool>,
169    /// Whether to show onboarding banners in the title bar.
170    ///
171    /// Default: true
172    pub show_onboarding_banner: Option<bool>,
173    /// Whether to show user avatar in the title bar.
174    ///
175    /// Default: true
176    pub show_user_picture: Option<bool>,
177    /// Whether to show the branch name button in the titlebar.
178    ///
179    /// Default: true
180    pub show_branch_name: Option<bool>,
181    /// Whether to show the project host and name in the titlebar.
182    ///
183    /// Default: true
184    pub show_project_items: Option<bool>,
185    /// Whether to show the sign in button in the title bar.
186    ///
187    /// Default: true
188    pub show_sign_in: Option<bool>,
189    /// Whether to show the menus in the title bar.
190    ///
191    /// Default: false
192    pub show_menus: Option<bool>,
193}
194
195#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
196#[serde(rename_all = "snake_case")]
197pub enum TitleBarVisibilityContent {
198    Always,
199    Never,
200    HideInFullScreen,
201}
202
203/// Configuration of audio in Zed.
204#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
205pub struct AudioSettingsContent {
206    /// Opt into the new audio system.
207    #[serde(rename = "experimental.rodio_audio", default)]
208    pub rodio_audio: Option<bool>,
209    /// Requires 'rodio_audio: true'
210    ///
211    /// Use the new audio systems automatic gain control for your microphone.
212    /// This affects how loud you sound to others.
213    #[serde(rename = "experimental.control_input_volume", default)]
214    pub control_input_volume: Option<bool>,
215    /// Requires 'rodio_audio: true'
216    ///
217    /// Use the new audio systems automatic gain control on everyone in the
218    /// call. This makes call members who are too quite louder and those who are
219    /// too loud quieter. This only affects how things sound for you.
220    #[serde(rename = "experimental.control_output_volume", default)]
221    pub control_output_volume: Option<bool>,
222}
223
224/// A custom Git hosting provider.
225#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
226pub struct GitHostingProviderConfig {
227    /// The type of the provider.
228    ///
229    /// Must be one of `github`, `gitlab`, or `bitbucket`.
230    pub provider: GitHostingProviderKind,
231
232    /// The base URL for the provider (e.g., "https://code.corp.big.com").
233    pub base_url: String,
234
235    /// The display name for the provider (e.g., "BigCorp GitHub").
236    pub name: String,
237}
238
239#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
240#[serde(rename_all = "snake_case")]
241pub enum GitHostingProviderKind {
242    Github,
243    Gitlab,
244    Bitbucket,
245}
246
247#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
248pub struct WorktreeSettingsContent {
249    /// The displayed name of this project. If not set, the root directory name
250    /// will be displayed.
251    ///
252    /// Default: none
253    pub project_name: Option<String>,
254
255    /// Completely ignore files matching globs from `file_scan_exclusions`. Overrides
256    /// `file_scan_inclusions`.
257    ///
258    /// Default: [
259    ///   "**/.git",
260    ///   "**/.svn",
261    ///   "**/.hg",
262    ///   "**/.jj",
263    ///   "**/CVS",
264    ///   "**/.DS_Store",
265    ///   "**/Thumbs.db",
266    ///   "**/.classpath",
267    ///   "**/.settings"
268    /// ]
269    pub file_scan_exclusions: Option<Vec<String>>,
270
271    /// Always include files that match these globs when scanning for files, even if they're
272    /// ignored by git. This setting is overridden by `file_scan_exclusions`.
273    /// Default: [
274    ///  ".env*",
275    ///  "docker-compose.*.yml",
276    /// ]
277    pub file_scan_inclusions: Option<Vec<String>>,
278
279    /// Treat the files matching these globs as `.env` files.
280    /// Default: [ "**/.env*" ]
281    pub private_files: Option<Vec<String>>,
282}
283/// Control what info is collected by Zed.
284#[derive(Default, Clone, Serialize, Deserialize, JsonSchema, Debug)]
285pub struct TelemetrySettingsContent {
286    /// Send debug info like crash reports.
287    ///
288    /// Default: true
289    pub diagnostics: Option<bool>,
290    /// Send anonymized usage data like what languages you're using Zed with.
291    ///
292    /// Default: true
293    pub metrics: Option<bool>,
294}
295
296#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
297pub struct DebuggerSettingsContent {
298    /// Determines the stepping granularity.
299    ///
300    /// Default: line
301    pub stepping_granularity: Option<SteppingGranularity>,
302    /// Whether the breakpoints should be reused across Zed sessions.
303    ///
304    /// Default: true
305    pub save_breakpoints: Option<bool>,
306    /// Whether to show the debug button in the status bar.
307    ///
308    /// Default: true
309    pub button: Option<bool>,
310    /// Time in milliseconds until timeout error when connecting to a TCP debug adapter
311    ///
312    /// Default: 2000ms
313    pub timeout: Option<u64>,
314    /// Whether to log messages between active debug adapters and Zed
315    ///
316    /// Default: true
317    pub log_dap_communications: Option<bool>,
318    /// Whether to format dap messages in when adding them to debug adapter logger
319    ///
320    /// Default: true
321    pub format_dap_log_messages: Option<bool>,
322    /// The dock position of the debug panel
323    ///
324    /// Default: Bottom
325    pub dock: Option<DockPosition>,
326}
327
328/// The granularity of one 'step' in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`.
329#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy, Deserialize, Serialize, JsonSchema)]
330#[serde(rename_all = "snake_case")]
331pub enum SteppingGranularity {
332    /// The step should allow the program to run until the current statement has finished executing.
333    /// The meaning of a statement is determined by the adapter and it may be considered equivalent to a line.
334    /// For example 'for(int i = 0; i < 10; i++)' could be considered to have 3 statements 'int i = 0', 'i < 10', and 'i++'.
335    Statement,
336    /// The step should allow the program to run until the current source line has executed.
337    Line,
338    /// The step should allow one instruction to execute (e.g. one x86 instruction).
339    Instruction,
340}
341
342#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
343#[serde(rename_all = "snake_case")]
344pub enum DockPosition {
345    Left,
346    Bottom,
347    Right,
348}