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