settings_content.rs

  1mod agent;
  2mod editor;
  3mod language;
  4mod project;
  5mod terminal;
  6mod theme;
  7mod workspace;
  8pub use agent::*;
  9pub use editor::*;
 10pub use language::*;
 11pub use project::*;
 12pub use terminal::*;
 13pub use theme::*;
 14pub use workspace::*;
 15
 16use collections::HashMap;
 17use gpui::{App, SharedString};
 18use release_channel::ReleaseChannel;
 19use schemars::JsonSchema;
 20use serde::{Deserialize, Serialize};
 21use std::env;
 22use std::sync::Arc;
 23pub use util::serde::default_true;
 24
 25use crate::ActiveSettingsProfileName;
 26
 27#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize, JsonSchema)]
 28pub struct SettingsContent {
 29    #[serde(flatten)]
 30    pub project: ProjectSettingsContent,
 31
 32    #[serde(flatten)]
 33    pub theme: Box<ThemeSettingsContent>,
 34
 35    #[serde(flatten)]
 36    pub extension: ExtensionSettingsContent,
 37
 38    #[serde(flatten)]
 39    pub workspace: WorkspaceSettingsContent,
 40
 41    #[serde(flatten)]
 42    pub editor: EditorSettingsContent,
 43
 44    pub tabs: Option<ItemSettingsContent>,
 45    pub tab_bar: Option<TabBarSettingsContent>,
 46
 47    pub preview_tabs: Option<PreviewTabsSettingsContent>,
 48
 49    pub agent: Option<AgentSettingsContent>,
 50    pub agent_servers: Option<AllAgentServersSettings>,
 51
 52    /// Configuration of audio in Zed.
 53    pub audio: Option<AudioSettingsContent>,
 54
 55    /// Whether or not to automatically check for updates.
 56    ///
 57    /// Default: true
 58    pub auto_update: Option<bool>,
 59
 60    // todo!() comments?!
 61    pub base_keymap: Option<BaseKeymapContent>,
 62
 63    pub debugger: Option<DebuggerSettingsContent>,
 64
 65    /// Configuration for Diagnostics-related features.
 66    pub diagnostics: Option<DiagnosticsSettingsContent>,
 67
 68    /// Configuration for Git-related features
 69    pub git: Option<GitSettings>,
 70
 71    /// Common language server settings.
 72    pub global_lsp_settings: Option<GlobalLspSettingsContent>,
 73
 74    /// Whether or not to enable Helix mode.
 75    ///
 76    /// Default: false
 77    pub helix_mode: Option<bool>,
 78    /// A map of log scopes to the desired log level.
 79    /// Useful for filtering out noisy logs or enabling more verbose logging.
 80    ///
 81    /// Example: {"log": {"client": "warn"}}
 82    pub log: Option<HashMap<String, String>>,
 83
 84    /// Configuration for Node-related features
 85    pub node: Option<NodeBinarySettings>,
 86
 87    pub proxy: Option<String>,
 88
 89    /// The URL of the Zed server to connect to.
 90    pub server_url: Option<String>,
 91
 92    /// Configuration for session-related features
 93    pub session: Option<SessionSettingsContent>,
 94    /// Control what info is collected by Zed.
 95    pub telemetry: Option<TelemetrySettingsContent>,
 96
 97    /// Configuration of the terminal in Zed.
 98    pub terminal: Option<TerminalSettingsContent>,
 99
100    pub title_bar: Option<TitleBarSettingsContent>,
101
102    /// Whether or not to enable Vim mode.
103    ///
104    /// Default: false
105    pub vim_mode: Option<bool>,
106
107    // Settings related to calls in Zed
108    pub calls: Option<CallSettingsContent>,
109
110    /// Whether to disable all AI features in Zed.
111    ///
112    /// Default: false
113    pub disable_ai: Option<bool>,
114}
115
116impl SettingsContent {
117    pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
118        &mut self.project.all_languages.languages.0
119    }
120}
121
122// todo!() what should this be?
123#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
124pub struct ServerSettingsContent {
125    #[serde(flatten)]
126    pub project: ProjectSettingsContent,
127}
128
129#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
130pub struct UserSettingsContent {
131    #[serde(flatten)]
132    pub content: Box<SettingsContent>,
133
134    pub dev: Option<Box<SettingsContent>>,
135    pub nightly: Option<Box<SettingsContent>>,
136    pub preview: Option<Box<SettingsContent>>,
137    pub stable: Option<Box<SettingsContent>>,
138
139    pub macos: Option<Box<SettingsContent>>,
140    pub windows: Option<Box<SettingsContent>>,
141    pub linux: Option<Box<SettingsContent>>,
142
143    #[serde(default)]
144    pub profiles: HashMap<String, SettingsContent>,
145}
146
147pub struct ExtensionsSettingsContent {
148    pub all_languages: AllLanguageSettingsContent,
149}
150
151impl UserSettingsContent {
152    pub fn for_release_channel(&self) -> Option<&SettingsContent> {
153        match *release_channel::RELEASE_CHANNEL {
154            ReleaseChannel::Dev => self.dev.as_deref(),
155            ReleaseChannel::Nightly => self.nightly.as_deref(),
156            ReleaseChannel::Preview => self.preview.as_deref(),
157            ReleaseChannel::Stable => self.stable.as_deref(),
158        }
159    }
160
161    pub fn for_os(&self) -> Option<&SettingsContent> {
162        match env::consts::OS {
163            "macos" => self.macos.as_deref(),
164            "linux" => self.linux.as_deref(),
165            "windows" => self.windows.as_deref(),
166            _ => None,
167        }
168    }
169
170    pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
171        let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
172            return None;
173        };
174        self.profiles.get(&active_profile.0)
175    }
176}
177
178/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
179///
180/// Default: VSCode
181#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
182pub enum BaseKeymapContent {
183    #[default]
184    VSCode,
185    JetBrains,
186    SublimeText,
187    Atom,
188    TextMate,
189    Emacs,
190    Cursor,
191    None,
192}
193
194#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
195pub struct TitleBarSettingsContent {
196    /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
197    ///
198    /// Default: "always"
199    pub show: Option<TitleBarVisibility>,
200    /// Whether to show the branch icon beside branch switcher in the title bar.
201    ///
202    /// Default: false
203    pub show_branch_icon: Option<bool>,
204    /// Whether to show onboarding banners in the title bar.
205    ///
206    /// Default: true
207    pub show_onboarding_banner: Option<bool>,
208    /// Whether to show user avatar in the title bar.
209    ///
210    /// Default: true
211    pub show_user_picture: Option<bool>,
212    /// Whether to show the branch name button in the titlebar.
213    ///
214    /// Default: true
215    pub show_branch_name: Option<bool>,
216    /// Whether to show the project host and name in the titlebar.
217    ///
218    /// Default: true
219    pub show_project_items: Option<bool>,
220    /// Whether to show the sign in button in the title bar.
221    ///
222    /// Default: true
223    pub show_sign_in: Option<bool>,
224    /// Whether to show the menus in the title bar.
225    ///
226    /// Default: false
227    pub show_menus: Option<bool>,
228}
229
230#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
231#[serde(rename_all = "snake_case")]
232pub enum TitleBarVisibility {
233    Always,
234    Never,
235    HideInFullScreen,
236}
237
238/// Configuration of audio in Zed.
239#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
240pub struct AudioSettingsContent {
241    /// Opt into the new audio system.
242    #[serde(rename = "experimental.rodio_audio", default)]
243    pub rodio_audio: Option<bool>,
244    /// Requires 'rodio_audio: true'
245    ///
246    /// Use the new audio systems automatic gain control for your microphone.
247    /// This affects how loud you sound to others.
248    #[serde(rename = "experimental.control_input_volume", default)]
249    pub control_input_volume: Option<bool>,
250    /// Requires 'rodio_audio: true'
251    ///
252    /// Use the new audio systems automatic gain control on everyone in the
253    /// call. This makes call members who are too quite louder and those who are
254    /// too loud quieter. This only affects how things sound for you.
255    #[serde(rename = "experimental.control_output_volume", default)]
256    pub control_output_volume: Option<bool>,
257}
258
259/// Control what info is collected by Zed.
260#[derive(Default, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Debug)]
261pub struct TelemetrySettingsContent {
262    /// Send debug info like crash reports.
263    ///
264    /// Default: true
265    pub diagnostics: Option<bool>,
266    /// Send anonymized usage data like what languages you're using Zed with.
267    ///
268    /// Default: true
269    pub metrics: Option<bool>,
270}
271
272#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Clone)]
273pub struct DebuggerSettingsContent {
274    /// Determines the stepping granularity.
275    ///
276    /// Default: line
277    pub stepping_granularity: Option<SteppingGranularity>,
278    /// Whether the breakpoints should be reused across Zed sessions.
279    ///
280    /// Default: true
281    pub save_breakpoints: Option<bool>,
282    /// Whether to show the debug button in the status bar.
283    ///
284    /// Default: true
285    pub button: Option<bool>,
286    /// Time in milliseconds until timeout error when connecting to a TCP debug adapter
287    ///
288    /// Default: 2000ms
289    pub timeout: Option<u64>,
290    /// Whether to log messages between active debug adapters and Zed
291    ///
292    /// Default: true
293    pub log_dap_communications: Option<bool>,
294    /// Whether to format dap messages in when adding them to debug adapter logger
295    ///
296    /// Default: true
297    pub format_dap_log_messages: Option<bool>,
298    /// The dock position of the debug panel
299    ///
300    /// Default: Bottom
301    pub dock: Option<DockPosition>,
302}
303
304/// The granularity of one 'step' in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`.
305#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy, Deserialize, Serialize, JsonSchema)]
306#[serde(rename_all = "snake_case")]
307pub enum SteppingGranularity {
308    /// The step should allow the program to run until the current statement has finished executing.
309    /// The meaning of a statement is determined by the adapter and it may be considered equivalent to a line.
310    /// For example 'for(int i = 0; i < 10; i++)' could be considered to have 3 statements 'int i = 0', 'i < 10', and 'i++'.
311    Statement,
312    /// The step should allow the program to run until the current source line has executed.
313    Line,
314    /// The step should allow one instruction to execute (e.g. one x86 instruction).
315    Instruction,
316}
317
318#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
319#[serde(rename_all = "snake_case")]
320pub enum DockPosition {
321    Left,
322    Bottom,
323    Right,
324}
325
326/// Settings for slash commands.
327#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, PartialEq, Eq)]
328pub struct SlashCommandSettings {
329    /// Settings for the `/cargo-workspace` slash command.
330    pub cargo_workspace: Option<CargoWorkspaceCommandSettings>,
331}
332
333/// Settings for the `/cargo-workspace` slash command.
334#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, PartialEq, Eq)]
335pub struct CargoWorkspaceCommandSettings {
336    /// Whether `/cargo-workspace` is enabled.
337    pub enabled: Option<bool>,
338}
339
340/// Configuration of voice calls in Zed.
341#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
342pub struct CallSettingsContent {
343    /// Whether the microphone should be muted when joining a channel or a call.
344    ///
345    /// Default: false
346    pub mute_on_join: Option<bool>,
347
348    /// Whether your current project should be shared when joining an empty channel.
349    ///
350    /// Default: false
351    pub share_on_join: Option<bool>,
352}
353
354#[derive(Deserialize, Serialize, PartialEq, Debug, Default, Clone, JsonSchema)]
355pub struct ExtensionSettingsContent {
356    /// The extensions that should be automatically installed by Zed.
357    ///
358    /// This is used to make functionality provided by extensions (e.g., language support)
359    /// available out-of-the-box.
360    ///
361    /// Default: { "html": true }
362    #[serde(default)]
363    pub auto_install_extensions: HashMap<Arc<str>, bool>,
364    #[serde(default)]
365    pub auto_update_extensions: HashMap<Arc<str>, bool>,
366}