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