settings_content.rs

   1mod agent;
   2mod editor;
   3mod extension;
   4mod language;
   5mod language_model;
   6mod project;
   7mod terminal;
   8mod theme;
   9mod workspace;
  10
  11pub use agent::*;
  12pub use editor::*;
  13pub use extension::*;
  14pub use language::*;
  15pub use language_model::*;
  16pub use project::*;
  17pub use terminal::*;
  18pub use theme::*;
  19pub use workspace::*;
  20
  21use collections::{HashMap, IndexMap};
  22use gpui::{App, SharedString};
  23use release_channel::ReleaseChannel;
  24use schemars::JsonSchema;
  25use serde::{Deserialize, Serialize};
  26use serde_with::skip_serializing_none;
  27use settings_macros::MergeFrom;
  28use std::collections::BTreeSet;
  29use std::env;
  30use std::sync::Arc;
  31pub use util::serde::default_true;
  32
  33use crate::{ActiveSettingsProfileName, merge_from};
  34
  35#[skip_serializing_none]
  36#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]
  37pub struct SettingsContent {
  38    #[serde(flatten)]
  39    pub project: ProjectSettingsContent,
  40
  41    #[serde(flatten)]
  42    pub theme: Box<ThemeSettingsContent>,
  43
  44    #[serde(flatten)]
  45    pub extension: ExtensionSettingsContent,
  46
  47    #[serde(flatten)]
  48    pub workspace: WorkspaceSettingsContent,
  49
  50    #[serde(flatten)]
  51    pub editor: EditorSettingsContent,
  52
  53    #[serde(flatten)]
  54    pub remote: RemoteSettingsContent,
  55
  56    /// Settings related to the file finder.
  57    pub file_finder: Option<FileFinderSettingsContent>,
  58
  59    pub git_panel: Option<GitPanelSettingsContent>,
  60
  61    pub tabs: Option<ItemSettingsContent>,
  62    pub tab_bar: Option<TabBarSettingsContent>,
  63    pub status_bar: Option<StatusBarSettingsContent>,
  64
  65    pub preview_tabs: Option<PreviewTabsSettingsContent>,
  66
  67    pub agent: Option<AgentSettingsContent>,
  68    pub agent_servers: Option<AllAgentServersSettings>,
  69
  70    /// Configuration of audio in Zed.
  71    pub audio: Option<AudioSettingsContent>,
  72
  73    /// Whether or not to automatically check for updates.
  74    ///
  75    /// Default: true
  76    pub auto_update: Option<bool>,
  77
  78    /// This base keymap settings adjusts the default keybindings in Zed to be similar
  79    /// to other common code editors. By default, Zed's keymap closely follows VSCode's
  80    /// keymap, with minor adjustments, this corresponds to the "VSCode" setting.
  81    ///
  82    /// Default: VSCode
  83    pub base_keymap: Option<BaseKeymapContent>,
  84
  85    /// Configuration for the collab panel visual settings.
  86    pub collaboration_panel: Option<PanelSettingsContent>,
  87
  88    pub debugger: Option<DebuggerSettingsContent>,
  89
  90    /// Configuration for Diagnostics-related features.
  91    pub diagnostics: Option<DiagnosticsSettingsContent>,
  92
  93    /// Configuration for Git-related features
  94    pub git: Option<GitSettings>,
  95
  96    /// Common language server settings.
  97    pub global_lsp_settings: Option<GlobalLspSettingsContent>,
  98
  99    /// The settings for the image viewer.
 100    pub image_viewer: Option<ImageViewerSettingsContent>,
 101
 102    pub repl: Option<ReplSettingsContent>,
 103
 104    /// Whether or not to enable Helix mode.
 105    ///
 106    /// Default: false
 107    pub helix_mode: Option<bool>,
 108
 109    pub journal: Option<JournalSettingsContent>,
 110
 111    /// A map of log scopes to the desired log level.
 112    /// Useful for filtering out noisy logs or enabling more verbose logging.
 113    ///
 114    /// Example: {"log": {"client": "warn"}}
 115    pub log: Option<HashMap<String, String>>,
 116
 117    pub line_indicator_format: Option<LineIndicatorFormat>,
 118
 119    pub language_models: Option<AllLanguageModelSettingsContent>,
 120
 121    pub outline_panel: Option<OutlinePanelSettingsContent>,
 122
 123    pub project_panel: Option<ProjectPanelSettingsContent>,
 124
 125    /// Configuration for the Message Editor
 126    pub message_editor: Option<MessageEditorSettings>,
 127
 128    /// Configuration for Node-related features
 129    pub node: Option<NodeBinarySettings>,
 130
 131    /// Configuration for the Notification Panel
 132    pub notification_panel: Option<NotificationPanelSettingsContent>,
 133
 134    pub proxy: Option<String>,
 135
 136    /// The URL of the Zed server to connect to.
 137    pub server_url: Option<String>,
 138
 139    /// Configuration for session-related features
 140    pub session: Option<SessionSettingsContent>,
 141    /// Control what info is collected by Zed.
 142    pub telemetry: Option<TelemetrySettingsContent>,
 143
 144    /// Configuration of the terminal in Zed.
 145    pub terminal: Option<TerminalSettingsContent>,
 146
 147    pub title_bar: Option<TitleBarSettingsContent>,
 148
 149    /// Whether or not to enable Vim mode.
 150    ///
 151    /// Default: false
 152    pub vim_mode: Option<bool>,
 153
 154    // Settings related to calls in Zed
 155    pub calls: Option<CallSettingsContent>,
 156
 157    /// Whether to disable all AI features in Zed.
 158    ///
 159    /// Default: false
 160    pub disable_ai: Option<SaturatingBool>,
 161
 162    /// Settings related to Vim mode in Zed.
 163    pub vim: Option<VimSettingsContent>,
 164}
 165
 166impl SettingsContent {
 167    pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
 168        &mut self.project.all_languages.languages.0
 169    }
 170}
 171
 172#[skip_serializing_none]
 173#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]
 174pub struct UserSettingsContent {
 175    #[serde(flatten)]
 176    pub content: Box<SettingsContent>,
 177
 178    pub dev: Option<Box<SettingsContent>>,
 179    pub nightly: Option<Box<SettingsContent>>,
 180    pub preview: Option<Box<SettingsContent>>,
 181    pub stable: Option<Box<SettingsContent>>,
 182
 183    pub macos: Option<Box<SettingsContent>>,
 184    pub windows: Option<Box<SettingsContent>>,
 185    pub linux: Option<Box<SettingsContent>>,
 186
 187    #[serde(default)]
 188    pub profiles: IndexMap<String, SettingsContent>,
 189}
 190
 191pub struct ExtensionsSettingsContent {
 192    pub all_languages: AllLanguageSettingsContent,
 193}
 194
 195impl UserSettingsContent {
 196    pub fn for_release_channel(&self) -> Option<&SettingsContent> {
 197        match *release_channel::RELEASE_CHANNEL {
 198            ReleaseChannel::Dev => self.dev.as_deref(),
 199            ReleaseChannel::Nightly => self.nightly.as_deref(),
 200            ReleaseChannel::Preview => self.preview.as_deref(),
 201            ReleaseChannel::Stable => self.stable.as_deref(),
 202        }
 203    }
 204
 205    pub fn for_os(&self) -> Option<&SettingsContent> {
 206        match env::consts::OS {
 207            "macos" => self.macos.as_deref(),
 208            "linux" => self.linux.as_deref(),
 209            "windows" => self.windows.as_deref(),
 210            _ => None,
 211        }
 212    }
 213
 214    pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
 215        let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
 216            return None;
 217        };
 218        self.profiles.get(&active_profile.0)
 219    }
 220}
 221
 222/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
 223///
 224/// Default: VSCode
 225#[derive(
 226    Copy,
 227    Clone,
 228    Debug,
 229    Serialize,
 230    Deserialize,
 231    JsonSchema,
 232    MergeFrom,
 233    PartialEq,
 234    Eq,
 235    Default,
 236    strum::VariantArray,
 237)]
 238pub enum BaseKeymapContent {
 239    #[default]
 240    VSCode,
 241    JetBrains,
 242    SublimeText,
 243    Atom,
 244    TextMate,
 245    Emacs,
 246    Cursor,
 247    None,
 248}
 249
 250impl strum::VariantNames for BaseKeymapContent {
 251    const VARIANTS: &'static [&'static str] = &[
 252        "VSCode",
 253        "JetBrains",
 254        "Sublime Text",
 255        "Atom",
 256        "TextMate",
 257        "Emacs",
 258        "Cursor",
 259        "None",
 260    ];
 261}
 262
 263#[skip_serializing_none]
 264#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
 265pub struct TitleBarSettingsContent {
 266    /// Whether to show the branch icon beside branch switcher in the title bar.
 267    ///
 268    /// Default: false
 269    pub show_branch_icon: Option<bool>,
 270    /// Whether to show onboarding banners in the title bar.
 271    ///
 272    /// Default: true
 273    pub show_onboarding_banner: Option<bool>,
 274    /// Whether to show user avatar in the title bar.
 275    ///
 276    /// Default: true
 277    pub show_user_picture: Option<bool>,
 278    /// Whether to show the branch name button in the titlebar.
 279    ///
 280    /// Default: true
 281    pub show_branch_name: Option<bool>,
 282    /// Whether to show the project host and name in the titlebar.
 283    ///
 284    /// Default: true
 285    pub show_project_items: Option<bool>,
 286    /// Whether to show the sign in button in the title bar.
 287    ///
 288    /// Default: true
 289    pub show_sign_in: Option<bool>,
 290    /// Whether to show the menus in the title bar.
 291    ///
 292    /// Default: false
 293    pub show_menus: Option<bool>,
 294}
 295
 296/// Configuration of audio in Zed.
 297#[skip_serializing_none]
 298#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
 299pub struct AudioSettingsContent {
 300    /// Opt into the new audio system.
 301    ///
 302    /// You need to rejoin a call for this setting to apply
 303    #[serde(rename = "experimental.rodio_audio")]
 304    pub rodio_audio: Option<bool>, // default is false
 305    /// Requires 'rodio_audio: true'
 306    ///
 307    /// Automatically increase or decrease you microphone's volume. This affects how
 308    /// loud you sound to others.
 309    ///
 310    /// Recommended: off (default)
 311    /// Microphones are too quite in zed, until everyone is on experimental
 312    /// audio and has auto speaker volume on this will make you very loud
 313    /// compared to other speakers.
 314    #[serde(rename = "experimental.auto_microphone_volume")]
 315    pub auto_microphone_volume: Option<bool>,
 316    /// Requires 'rodio_audio: true'
 317    ///
 318    /// Automatically increate or decrease the volume of other call members.
 319    /// This only affects how things sound for you.
 320    #[serde(rename = "experimental.auto_speaker_volume")]
 321    pub auto_speaker_volume: Option<bool>,
 322    /// Requires 'rodio_audio: true'
 323    ///
 324    /// Remove background noises. Works great for typing, cars, dogs, AC. Does
 325    /// not work well on music.
 326    #[serde(rename = "experimental.denoise")]
 327    pub denoise: Option<bool>,
 328    /// Requires 'rodio_audio: true'
 329    ///
 330    /// Use audio parameters compatible with the previous versions of
 331    /// experimental audio and non-experimental audio. When this is false you
 332    /// will sound strange to anyone not on the latest experimental audio. In
 333    /// the future we will migrate by setting this to false
 334    ///
 335    /// You need to rejoin a call for this setting to apply
 336    #[serde(rename = "experimental.legacy_audio_compatible")]
 337    pub legacy_audio_compatible: Option<bool>,
 338}
 339
 340/// Control what info is collected by Zed.
 341#[skip_serializing_none]
 342#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Debug, MergeFrom)]
 343pub struct TelemetrySettingsContent {
 344    /// Send debug info like crash reports.
 345    ///
 346    /// Default: true
 347    pub diagnostics: Option<bool>,
 348    /// Send anonymized usage data like what languages you're using Zed with.
 349    ///
 350    /// Default: true
 351    pub metrics: Option<bool>,
 352}
 353
 354impl Default for TelemetrySettingsContent {
 355    fn default() -> Self {
 356        Self {
 357            diagnostics: Some(true),
 358            metrics: Some(true),
 359        }
 360    }
 361}
 362
 363#[skip_serializing_none]
 364#[derive(Default, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Clone, MergeFrom)]
 365pub struct DebuggerSettingsContent {
 366    /// Determines the stepping granularity.
 367    ///
 368    /// Default: line
 369    pub stepping_granularity: Option<SteppingGranularity>,
 370    /// Whether the breakpoints should be reused across Zed sessions.
 371    ///
 372    /// Default: true
 373    pub save_breakpoints: Option<bool>,
 374    /// Whether to show the debug button in the status bar.
 375    ///
 376    /// Default: true
 377    pub button: Option<bool>,
 378    /// Time in milliseconds until timeout error when connecting to a TCP debug adapter
 379    ///
 380    /// Default: 2000ms
 381    pub timeout: Option<u64>,
 382    /// Whether to log messages between active debug adapters and Zed
 383    ///
 384    /// Default: true
 385    pub log_dap_communications: Option<bool>,
 386    /// Whether to format dap messages in when adding them to debug adapter logger
 387    ///
 388    /// Default: true
 389    pub format_dap_log_messages: Option<bool>,
 390    /// The dock position of the debug panel
 391    ///
 392    /// Default: Bottom
 393    pub dock: Option<DockPosition>,
 394}
 395
 396/// The granularity of one 'step' in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`.
 397#[derive(
 398    PartialEq,
 399    Eq,
 400    Debug,
 401    Hash,
 402    Clone,
 403    Copy,
 404    Deserialize,
 405    Serialize,
 406    JsonSchema,
 407    MergeFrom,
 408    strum::VariantArray,
 409    strum::VariantNames,
 410)]
 411#[serde(rename_all = "snake_case")]
 412pub enum SteppingGranularity {
 413    /// The step should allow the program to run until the current statement has finished executing.
 414    /// The meaning of a statement is determined by the adapter and it may be considered equivalent to a line.
 415    /// For example 'for(int i = 0; i < 10; i++)' could be considered to have 3 statements 'int i = 0', 'i < 10', and 'i++'.
 416    Statement,
 417    /// The step should allow the program to run until the current source line has executed.
 418    Line,
 419    /// The step should allow one instruction to execute (e.g. one x86 instruction).
 420    Instruction,
 421}
 422
 423#[derive(
 424    Copy,
 425    Clone,
 426    Debug,
 427    Serialize,
 428    Deserialize,
 429    JsonSchema,
 430    MergeFrom,
 431    PartialEq,
 432    Eq,
 433    strum::VariantArray,
 434    strum::VariantNames,
 435)]
 436#[serde(rename_all = "snake_case")]
 437pub enum DockPosition {
 438    Left,
 439    Bottom,
 440    Right,
 441}
 442
 443/// Settings for slash commands.
 444#[skip_serializing_none]
 445#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, MergeFrom, PartialEq, Eq)]
 446pub struct SlashCommandSettings {
 447    /// Settings for the `/cargo-workspace` slash command.
 448    pub cargo_workspace: Option<CargoWorkspaceCommandSettings>,
 449}
 450
 451/// Settings for the `/cargo-workspace` slash command.
 452#[skip_serializing_none]
 453#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema, MergeFrom, PartialEq, Eq)]
 454pub struct CargoWorkspaceCommandSettings {
 455    /// Whether `/cargo-workspace` is enabled.
 456    pub enabled: Option<bool>,
 457}
 458
 459/// Configuration of voice calls in Zed.
 460#[skip_serializing_none]
 461#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
 462pub struct CallSettingsContent {
 463    /// Whether the microphone should be muted when joining a channel or a call.
 464    ///
 465    /// Default: false
 466    pub mute_on_join: Option<bool>,
 467
 468    /// Whether your current project should be shared when joining an empty channel.
 469    ///
 470    /// Default: false
 471    pub share_on_join: Option<bool>,
 472}
 473
 474#[skip_serializing_none]
 475#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
 476pub struct GitPanelSettingsContent {
 477    /// Whether to show the panel button in the status bar.
 478    ///
 479    /// Default: true
 480    pub button: Option<bool>,
 481    /// Where to dock the panel.
 482    ///
 483    /// Default: left
 484    pub dock: Option<DockPosition>,
 485    /// Default width of the panel in pixels.
 486    ///
 487    /// Default: 360
 488    pub default_width: Option<f32>,
 489    /// How entry statuses are displayed.
 490    ///
 491    /// Default: icon
 492    pub status_style: Option<StatusStyle>,
 493    /// How and when the scrollbar should be displayed.
 494    ///
 495    /// Default: inherits editor scrollbar settings
 496    pub scrollbar: Option<ScrollbarSettings>,
 497
 498    /// What the default branch name should be when
 499    /// `init.defaultBranch` is not set in git
 500    ///
 501    /// Default: main
 502    pub fallback_branch_name: Option<String>,
 503
 504    /// Whether to sort entries in the panel by path
 505    /// or by status (the default).
 506    ///
 507    /// Default: false
 508    pub sort_by_path: Option<bool>,
 509
 510    /// Whether to collapse untracked files in the diff panel.
 511    ///
 512    /// Default: false
 513    pub collapse_untracked_diff: Option<bool>,
 514}
 515
 516#[derive(
 517    Default,
 518    Copy,
 519    Clone,
 520    Debug,
 521    Serialize,
 522    Deserialize,
 523    JsonSchema,
 524    MergeFrom,
 525    PartialEq,
 526    Eq,
 527    strum::VariantArray,
 528    strum::VariantNames,
 529)]
 530#[serde(rename_all = "snake_case")]
 531pub enum StatusStyle {
 532    #[default]
 533    Icon,
 534    LabelColor,
 535}
 536
 537#[skip_serializing_none]
 538#[derive(
 539    Copy, Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
 540)]
 541pub struct ScrollbarSettings {
 542    pub show: Option<ShowScrollbar>,
 543}
 544
 545#[skip_serializing_none]
 546#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
 547pub struct NotificationPanelSettingsContent {
 548    /// Whether to show the panel button in the status bar.
 549    ///
 550    /// Default: true
 551    pub button: Option<bool>,
 552    /// Where to dock the panel.
 553    ///
 554    /// Default: right
 555    pub dock: Option<DockPosition>,
 556    /// Default width of the panel in pixels.
 557    ///
 558    /// Default: 300
 559    pub default_width: Option<f32>,
 560}
 561
 562#[skip_serializing_none]
 563#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
 564pub struct PanelSettingsContent {
 565    /// Whether to show the panel button in the status bar.
 566    ///
 567    /// Default: true
 568    pub button: Option<bool>,
 569    /// Where to dock the panel.
 570    ///
 571    /// Default: left
 572    pub dock: Option<DockPosition>,
 573    /// Default width of the panel in pixels.
 574    ///
 575    /// Default: 240
 576    pub default_width: Option<f32>,
 577}
 578
 579#[skip_serializing_none]
 580#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
 581pub struct MessageEditorSettings {
 582    /// Whether to automatically replace emoji shortcodes with emoji characters.
 583    /// For example: typing `:wave:` gets replaced with `👋`.
 584    ///
 585    /// Default: false
 586    pub auto_replace_emoji_shortcode: Option<bool>,
 587}
 588
 589#[skip_serializing_none]
 590#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
 591pub struct FileFinderSettingsContent {
 592    /// Whether to show file icons in the file finder.
 593    ///
 594    /// Default: true
 595    pub file_icons: Option<bool>,
 596    /// Determines how much space the file finder can take up in relation to the available window width.
 597    ///
 598    /// Default: small
 599    pub modal_max_width: Option<FileFinderWidthContent>,
 600    /// Determines whether the file finder should skip focus for the active file in search results.
 601    ///
 602    /// Default: true
 603    pub skip_focus_for_active_in_search: Option<bool>,
 604    /// Determines whether to show the git status in the file finder
 605    ///
 606    /// Default: true
 607    pub git_status: Option<bool>,
 608    /// Whether to use gitignored files when searching.
 609    /// Only the file Zed had indexed will be used, not necessary all the gitignored files.
 610    ///
 611    /// Default: Smart
 612    pub include_ignored: Option<IncludeIgnoredContent>,
 613}
 614
 615#[derive(
 616    Debug,
 617    PartialEq,
 618    Eq,
 619    Clone,
 620    Copy,
 621    Default,
 622    Serialize,
 623    Deserialize,
 624    JsonSchema,
 625    MergeFrom,
 626    strum::VariantArray,
 627    strum::VariantNames,
 628)]
 629#[serde(rename_all = "snake_case")]
 630pub enum IncludeIgnoredContent {
 631    /// Use all gitignored files
 632    All,
 633    /// Use only the files Zed had indexed
 634    Indexed,
 635    /// Be smart and search for ignored when called from a gitignored worktree
 636    #[default]
 637    Smart,
 638}
 639
 640#[derive(
 641    Debug,
 642    PartialEq,
 643    Eq,
 644    Clone,
 645    Copy,
 646    Default,
 647    Serialize,
 648    Deserialize,
 649    JsonSchema,
 650    MergeFrom,
 651    strum::VariantArray,
 652    strum::VariantNames,
 653)]
 654#[serde(rename_all = "lowercase")]
 655pub enum FileFinderWidthContent {
 656    #[default]
 657    Small,
 658    Medium,
 659    Large,
 660    XLarge,
 661    Full,
 662}
 663
 664#[skip_serializing_none]
 665#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Debug, JsonSchema, MergeFrom)]
 666pub struct VimSettingsContent {
 667    pub default_mode: Option<ModeContent>,
 668    pub toggle_relative_line_numbers: Option<bool>,
 669    pub use_system_clipboard: Option<UseSystemClipboard>,
 670    pub use_smartcase_find: Option<bool>,
 671    pub custom_digraphs: Option<HashMap<String, Arc<str>>>,
 672    pub highlight_on_yank_duration: Option<u64>,
 673    pub cursor_shape: Option<CursorShapeSettings>,
 674}
 675
 676#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Debug)]
 677#[serde(rename_all = "snake_case")]
 678pub enum ModeContent {
 679    #[default]
 680    Normal,
 681    Insert,
 682}
 683
 684/// Controls when to use system clipboard.
 685#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
 686#[serde(rename_all = "snake_case")]
 687pub enum UseSystemClipboard {
 688    /// Don't use system clipboard.
 689    Never,
 690    /// Use system clipboard.
 691    Always,
 692    /// Use system clipboard for yank operations.
 693    OnYank,
 694}
 695
 696/// The settings for cursor shape.
 697#[skip_serializing_none]
 698#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
 699pub struct CursorShapeSettings {
 700    /// Cursor shape for the normal mode.
 701    ///
 702    /// Default: block
 703    pub normal: Option<CursorShape>,
 704    /// Cursor shape for the replace mode.
 705    ///
 706    /// Default: underline
 707    pub replace: Option<CursorShape>,
 708    /// Cursor shape for the visual mode.
 709    ///
 710    /// Default: block
 711    pub visual: Option<CursorShape>,
 712    /// Cursor shape for the insert mode.
 713    ///
 714    /// The default value follows the primary cursor_shape.
 715    pub insert: Option<CursorShape>,
 716}
 717
 718/// Settings specific to journaling
 719#[skip_serializing_none]
 720#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
 721pub struct JournalSettingsContent {
 722    /// The path of the directory where journal entries are stored.
 723    ///
 724    /// Default: `~`
 725    pub path: Option<String>,
 726    /// What format to display the hours in.
 727    ///
 728    /// Default: hour12
 729    pub hour_format: Option<HourFormat>,
 730}
 731
 732#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
 733#[serde(rename_all = "snake_case")]
 734pub enum HourFormat {
 735    #[default]
 736    Hour12,
 737    Hour24,
 738}
 739
 740#[skip_serializing_none]
 741#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
 742pub struct OutlinePanelSettingsContent {
 743    /// Whether to show the outline panel button in the status bar.
 744    ///
 745    /// Default: true
 746    pub button: Option<bool>,
 747    /// Customize default width (in pixels) taken by outline panel
 748    ///
 749    /// Default: 240
 750    pub default_width: Option<f32>,
 751    /// The position of outline panel
 752    ///
 753    /// Default: left
 754    pub dock: Option<DockSide>,
 755    /// Whether to show file icons in the outline panel.
 756    ///
 757    /// Default: true
 758    pub file_icons: Option<bool>,
 759    /// Whether to show folder icons or chevrons for directories in the outline panel.
 760    ///
 761    /// Default: true
 762    pub folder_icons: Option<bool>,
 763    /// Whether to show the git status in the outline panel.
 764    ///
 765    /// Default: true
 766    pub git_status: Option<bool>,
 767    /// Amount of indentation (in pixels) for nested items.
 768    ///
 769    /// Default: 20
 770    pub indent_size: Option<f32>,
 771    /// Whether to reveal it in the outline panel automatically,
 772    /// when a corresponding project entry becomes active.
 773    /// Gitignored entries are never auto revealed.
 774    ///
 775    /// Default: true
 776    pub auto_reveal_entries: Option<bool>,
 777    /// Whether to fold directories automatically
 778    /// when directory has only one directory inside.
 779    ///
 780    /// Default: true
 781    pub auto_fold_dirs: Option<bool>,
 782    /// Settings related to indent guides in the outline panel.
 783    pub indent_guides: Option<IndentGuidesSettingsContent>,
 784    /// Scrollbar-related settings
 785    pub scrollbar: Option<ScrollbarSettingsContent>,
 786    /// Default depth to expand outline items in the current file.
 787    /// The default depth to which outline entries are expanded on reveal.
 788    /// - Set to 0 to collapse all items that have children
 789    /// - Set to 1 or higher to collapse items at that depth or deeper
 790    ///
 791    /// Default: 100
 792    pub expand_outlines_with_depth: Option<usize>,
 793}
 794
 795#[derive(
 796    Clone,
 797    Copy,
 798    Debug,
 799    PartialEq,
 800    Eq,
 801    Serialize,
 802    Deserialize,
 803    JsonSchema,
 804    MergeFrom,
 805    strum::VariantArray,
 806    strum::VariantNames,
 807)]
 808#[serde(rename_all = "snake_case")]
 809pub enum DockSide {
 810    Left,
 811    Right,
 812}
 813
 814#[derive(
 815    Copy,
 816    Clone,
 817    Debug,
 818    PartialEq,
 819    Eq,
 820    Deserialize,
 821    Serialize,
 822    JsonSchema,
 823    MergeFrom,
 824    strum::VariantArray,
 825    strum::VariantNames,
 826)]
 827#[serde(rename_all = "snake_case")]
 828pub enum ShowIndentGuides {
 829    Always,
 830    Never,
 831}
 832
 833#[skip_serializing_none]
 834#[derive(
 835    Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default,
 836)]
 837pub struct IndentGuidesSettingsContent {
 838    /// When to show the scrollbar in the outline panel.
 839    pub show: Option<ShowIndentGuides>,
 840}
 841
 842#[derive(Clone, Copy, Default, PartialEq, Debug, JsonSchema, MergeFrom, Deserialize, Serialize)]
 843#[serde(rename_all = "snake_case")]
 844pub enum LineIndicatorFormat {
 845    Short,
 846    #[default]
 847    Long,
 848}
 849
 850/// The settings for the image viewer.
 851#[skip_serializing_none]
 852#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, Default, PartialEq)]
 853pub struct ImageViewerSettingsContent {
 854    /// The unit to use for displaying image file sizes.
 855    ///
 856    /// Default: "binary"
 857    pub unit: Option<ImageFileSizeUnit>,
 858}
 859
 860#[skip_serializing_none]
 861#[derive(
 862    Clone,
 863    Copy,
 864    Debug,
 865    Serialize,
 866    Deserialize,
 867    JsonSchema,
 868    MergeFrom,
 869    Default,
 870    PartialEq,
 871    strum::VariantArray,
 872    strum::VariantNames,
 873)]
 874#[serde(rename_all = "snake_case")]
 875pub enum ImageFileSizeUnit {
 876    /// Displays file size in binary units (e.g., KiB, MiB).
 877    #[default]
 878    Binary,
 879    /// Displays file size in decimal units (e.g., KB, MB).
 880    Decimal,
 881}
 882
 883#[skip_serializing_none]
 884#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
 885pub struct RemoteSettingsContent {
 886    pub ssh_connections: Option<Vec<SshConnection>>,
 887    pub wsl_connections: Option<Vec<WslConnection>>,
 888    pub read_ssh_config: Option<bool>,
 889}
 890
 891#[skip_serializing_none]
 892#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
 893pub struct SshConnection {
 894    pub host: SharedString,
 895    pub username: Option<String>,
 896    pub port: Option<u16>,
 897    #[serde(default)]
 898    pub args: Vec<String>,
 899    #[serde(default)]
 900    pub projects: collections::BTreeSet<SshProject>,
 901    /// Name to use for this server in UI.
 902    pub nickname: Option<String>,
 903    // By default Zed will download the binary to the host directly.
 904    // If this is set to true, Zed will download the binary to your local machine,
 905    // and then upload it over the SSH connection. Useful if your SSH server has
 906    // limited outbound internet access.
 907    pub upload_binary_over_ssh: Option<bool>,
 908
 909    pub port_forwards: Option<Vec<SshPortForwardOption>>,
 910}
 911
 912#[derive(Clone, Default, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom, Debug)]
 913pub struct WslConnection {
 914    pub distro_name: SharedString,
 915    pub user: Option<String>,
 916    #[serde(default)]
 917    pub projects: BTreeSet<SshProject>,
 918}
 919
 920#[skip_serializing_none]
 921#[derive(
 922    Clone, Debug, Default, Serialize, PartialEq, Eq, PartialOrd, Ord, Deserialize, JsonSchema,
 923)]
 924pub struct SshProject {
 925    pub paths: Vec<String>,
 926}
 927
 928#[skip_serializing_none]
 929#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, JsonSchema, MergeFrom)]
 930pub struct SshPortForwardOption {
 931    #[serde(skip_serializing_if = "Option::is_none")]
 932    pub local_host: Option<String>,
 933    pub local_port: u16,
 934    #[serde(skip_serializing_if = "Option::is_none")]
 935    pub remote_host: Option<String>,
 936    pub remote_port: u16,
 937}
 938
 939/// Settings for configuring REPL display and behavior.
 940#[skip_serializing_none]
 941#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
 942pub struct ReplSettingsContent {
 943    /// Maximum number of lines to keep in REPL's scrollback buffer.
 944    /// Clamped with [4, 256] range.
 945    ///
 946    /// Default: 32
 947    pub max_lines: Option<usize>,
 948    /// Maximum number of columns to keep in REPL's scrollback buffer.
 949    /// Clamped with [20, 512] range.
 950    ///
 951    /// Default: 128
 952    pub max_columns: Option<usize>,
 953}
 954
 955#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
 956/// An ExtendingVec in the settings can only accumulate new values.
 957///
 958/// This is useful for things like private files where you only want
 959/// to allow new values to be added.
 960///
 961/// Consider using a HashMap<String, bool> instead of this type
 962/// (like auto_install_extensions) so that user settings files can both add
 963/// and remove values from the set.
 964pub struct ExtendingVec<T>(pub Vec<T>);
 965
 966impl<T> Into<Vec<T>> for ExtendingVec<T> {
 967    fn into(self) -> Vec<T> {
 968        self.0
 969    }
 970}
 971impl<T> From<Vec<T>> for ExtendingVec<T> {
 972    fn from(vec: Vec<T>) -> Self {
 973        ExtendingVec(vec)
 974    }
 975}
 976
 977impl<T: Clone> merge_from::MergeFrom for ExtendingVec<T> {
 978    fn merge_from(&mut self, other: &Self) {
 979        self.0.extend_from_slice(other.0.as_slice());
 980    }
 981}
 982
 983/// A SaturatingBool in the settings can only ever be set to true,
 984/// later attempts to set it to false will be ignored.
 985///
 986/// Used by `disable_ai`.
 987#[derive(Debug, Default, Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
 988pub struct SaturatingBool(pub bool);
 989
 990impl From<bool> for SaturatingBool {
 991    fn from(value: bool) -> Self {
 992        SaturatingBool(value)
 993    }
 994}
 995
 996impl From<SaturatingBool> for bool {
 997    fn from(value: SaturatingBool) -> bool {
 998        value.0
 999    }
1000}
1001
1002impl merge_from::MergeFrom for SaturatingBool {
1003    fn merge_from(&mut self, other: &Self) {
1004        self.0 |= other.0
1005    }
1006}
1007
1008#[derive(
1009    Copy,
1010    Clone,
1011    Default,
1012    Debug,
1013    PartialEq,
1014    Eq,
1015    PartialOrd,
1016    Ord,
1017    Serialize,
1018    Deserialize,
1019    MergeFrom,
1020    JsonSchema,
1021    derive_more::FromStr,
1022)]
1023#[serde(transparent)]
1024pub struct DelayMs(pub u64);
1025
1026impl From<u64> for DelayMs {
1027    fn from(n: u64) -> Self {
1028        Self(n)
1029    }
1030}
1031
1032impl std::fmt::Display for DelayMs {
1033    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1034        write!(f, "{}ms", self.0)
1035    }
1036}
1037
1038/// A wrapper type that distinguishes between an explicitly set value (including null) and an unset value.
1039///
1040/// This is useful for configuration where you need to differentiate between:
1041/// - A field that is not present in the configuration file (`Maybe::Unset`)
1042/// - A field that is explicitly set to `null` (`Maybe::Set(None)`)
1043/// - A field that is explicitly set to a value (`Maybe::Set(Some(value))`)
1044///
1045/// # Examples
1046///
1047/// In JSON:
1048/// - `{}` (field missing) deserializes to `Maybe::Unset`
1049/// - `{"field": null}` deserializes to `Maybe::Set(None)`
1050/// - `{"field": "value"}` deserializes to `Maybe::Set(Some("value"))`
1051///
1052/// WARN: This type should not be wrapped in an option inside of settings, otherwise the default `serde_json` behavior
1053/// of treating `null` and missing as the `Option::None` will be used
1054#[derive(Debug, Clone, PartialEq, Eq, strum::EnumDiscriminants, Default)]
1055#[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))]
1056pub enum Maybe<T> {
1057    /// An explicitly set value, which may be `None` (representing JSON `null`) or `Some(value)`.
1058    Set(Option<T>),
1059    /// A value that was not present in the configuration.
1060    #[default]
1061    Unset,
1062}
1063
1064impl<T: Clone> merge_from::MergeFrom for Maybe<T> {
1065    fn merge_from(&mut self, other: &Self) {
1066        if self.is_unset() {
1067            *self = other.clone();
1068        }
1069    }
1070}
1071
1072impl<T> From<Option<Option<T>>> for Maybe<T> {
1073    fn from(value: Option<Option<T>>) -> Self {
1074        match value {
1075            Some(value) => Maybe::Set(value),
1076            None => Maybe::Unset,
1077        }
1078    }
1079}
1080
1081impl<T> Maybe<T> {
1082    pub fn is_set(&self) -> bool {
1083        matches!(self, Maybe::Set(_))
1084    }
1085
1086    pub fn is_unset(&self) -> bool {
1087        matches!(self, Maybe::Unset)
1088    }
1089
1090    pub fn into_inner(self) -> Option<T> {
1091        match self {
1092            Maybe::Set(value) => value,
1093            Maybe::Unset => None,
1094        }
1095    }
1096
1097    pub fn as_ref(&self) -> Option<&Option<T>> {
1098        match self {
1099            Maybe::Set(value) => Some(value),
1100            Maybe::Unset => None,
1101        }
1102    }
1103}
1104
1105impl<T: serde::Serialize> serde::Serialize for Maybe<T> {
1106    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1107    where
1108        S: serde::Serializer,
1109    {
1110        match self {
1111            Maybe::Set(value) => value.serialize(serializer),
1112            Maybe::Unset => serializer.serialize_none(),
1113        }
1114    }
1115}
1116
1117impl<'de, T: serde::Deserialize<'de>> serde::Deserialize<'de> for Maybe<T> {
1118    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1119    where
1120        D: serde::Deserializer<'de>,
1121    {
1122        Option::<T>::deserialize(deserializer).map(Maybe::Set)
1123    }
1124}
1125
1126impl<T: JsonSchema> JsonSchema for Maybe<T> {
1127    fn schema_name() -> std::borrow::Cow<'static, str> {
1128        format!("Nullable<{}>", T::schema_name()).into()
1129    }
1130
1131    fn json_schema(generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
1132        let mut schema = generator.subschema_for::<Option<T>>();
1133        // Add description explaining that null is an explicit value
1134        let description = if let Some(existing_desc) =
1135            schema.get("description").and_then(|desc| desc.as_str())
1136        {
1137            format!(
1138                "{}. Note: `null` is treated as an explicit value, different from omitting the field entirely.",
1139                existing_desc
1140            )
1141        } else {
1142            "This field supports explicit `null` values. Omitting the field is different from setting it to `null`.".to_string()
1143        };
1144
1145        schema.insert("description".to_string(), description.into());
1146
1147        schema
1148    }
1149}
1150
1151#[cfg(test)]
1152mod tests {
1153    use super::*;
1154    use serde_json;
1155
1156    #[test]
1157    fn test_maybe() {
1158        #[derive(Debug, PartialEq, Serialize, Deserialize)]
1159        struct TestStruct {
1160            #[serde(default)]
1161            #[serde(skip_serializing_if = "Maybe::is_unset")]
1162            field: Maybe<String>,
1163        }
1164
1165        #[derive(Debug, PartialEq, Serialize, Deserialize)]
1166        struct NumericTest {
1167            #[serde(default)]
1168            value: Maybe<i32>,
1169        }
1170
1171        let json = "{}";
1172        let result: TestStruct = serde_json::from_str(json).unwrap();
1173        assert!(result.field.is_unset());
1174        assert_eq!(result.field, Maybe::Unset);
1175
1176        let json = r#"{"field": null}"#;
1177        let result: TestStruct = serde_json::from_str(json).unwrap();
1178        assert!(result.field.is_set());
1179        assert_eq!(result.field, Maybe::Set(None));
1180
1181        let json = r#"{"field": "hello"}"#;
1182        let result: TestStruct = serde_json::from_str(json).unwrap();
1183        assert!(result.field.is_set());
1184        assert_eq!(result.field, Maybe::Set(Some("hello".to_string())));
1185
1186        let test = TestStruct {
1187            field: Maybe::Unset,
1188        };
1189        let json = serde_json::to_string(&test).unwrap();
1190        assert_eq!(json, "{}");
1191
1192        let test = TestStruct {
1193            field: Maybe::Set(None),
1194        };
1195        let json = serde_json::to_string(&test).unwrap();
1196        assert_eq!(json, r#"{"field":null}"#);
1197
1198        let test = TestStruct {
1199            field: Maybe::Set(Some("world".to_string())),
1200        };
1201        let json = serde_json::to_string(&test).unwrap();
1202        assert_eq!(json, r#"{"field":"world"}"#);
1203
1204        let default_maybe: Maybe<i32> = Maybe::default();
1205        assert!(default_maybe.is_unset());
1206
1207        let unset: Maybe<String> = Maybe::Unset;
1208        assert!(unset.is_unset());
1209        assert!(!unset.is_set());
1210
1211        let set_none: Maybe<String> = Maybe::Set(None);
1212        assert!(set_none.is_set());
1213        assert!(!set_none.is_unset());
1214
1215        let set_some: Maybe<String> = Maybe::Set(Some("value".to_string()));
1216        assert!(set_some.is_set());
1217        assert!(!set_some.is_unset());
1218
1219        let original = TestStruct {
1220            field: Maybe::Set(Some("test".to_string())),
1221        };
1222        let json = serde_json::to_string(&original).unwrap();
1223        let deserialized: TestStruct = serde_json::from_str(&json).unwrap();
1224        assert_eq!(original, deserialized);
1225
1226        let json = r#"{"value": 42}"#;
1227        let result: NumericTest = serde_json::from_str(json).unwrap();
1228        assert_eq!(result.value, Maybe::Set(Some(42)));
1229
1230        let json = r#"{"value": null}"#;
1231        let result: NumericTest = serde_json::from_str(json).unwrap();
1232        assert_eq!(result.value, Maybe::Set(None));
1233
1234        let json = "{}";
1235        let result: NumericTest = serde_json::from_str(json).unwrap();
1236        assert_eq!(result.value, Maybe::Unset);
1237
1238        // Test JsonSchema implementation
1239        use schemars::schema_for;
1240        let schema = schema_for!(Maybe<String>);
1241        let schema_json = serde_json::to_value(&schema).unwrap();
1242
1243        // Verify the description mentions that null is an explicit value
1244        let description = schema_json["description"].as_str().unwrap();
1245        assert!(
1246            description.contains("null") && description.contains("explicit"),
1247            "Schema description should mention that null is an explicit value. Got: {}",
1248            description
1249        );
1250    }
1251}