settings_content.rs

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