1271 lines · 36.1 KB · Rust
RawDownload
mod agent;mod editor;mod extension;mod fallible_options;mod language;mod language_model;pub mod merge_from;mod project;mod serde_helper;mod terminal;mod theme;mod workspace; pub use agent::*;pub use editor::*;pub use extension::*;pub use fallible_options::*;pub use language::*;pub use language_model::*;pub use merge_from::MergeFrom as MergeFromTrait;pub use project::*;use serde::de::DeserializeOwned;pub use serde_helper::{    serialize_f32_with_two_decimal_places, serialize_optional_f32_with_two_decimal_places,};use settings_json::parse_json_with_comments;pub use terminal::*;pub use theme::*;pub use workspace::*; use collections::{HashMap, IndexMap};use schemars::JsonSchema;use serde::{Deserialize, Serialize};use settings_macros::{MergeFrom, with_fallible_options}; /// Defines a settings override struct where each field is/// `Option<Box<SettingsContent>>`, along with:/// - `OVERRIDE_KEYS`: a `&[&str]` of the field names (the JSON keys)/// - `get_by_key(&self, key) -> Option<&SettingsContent>`: accessor by key////// The field list is the single source of truth for the override key strings.macro_rules! settings_overrides {    (        $(#[$attr:meta])*        pub struct $name:ident { $($field:ident),* $(,)? }    ) => {        $(#[$attr])*        pub struct $name {            $(pub $field: Option<Box<SettingsContent>>,)*        }         impl $name {            /// The JSON override keys, derived from the field names on this struct.            pub const OVERRIDE_KEYS: &[&str] = &[$(stringify!($field)),*];             /// Look up an override by its JSON key name.            pub fn get_by_key(&self, key: &str) -> Option<&SettingsContent> {                match key {                    $(stringify!($field) => self.$field.as_deref(),)*                    _ => None,                }            }        }    }}use std::collections::BTreeSet;use std::sync::Arc;pub use util::serde::default_true; #[derive(Debug, Clone, PartialEq, Eq)]pub enum ParseStatus {    /// Settings were parsed successfully    Success,    /// Settings failed to parse    Failed { error: String },} #[with_fallible_options]#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct SettingsContent {    #[serde(flatten)]    pub project: ProjectSettingsContent,     #[serde(flatten)]    pub theme: Box<ThemeSettingsContent>,     #[serde(flatten)]    pub extension: ExtensionSettingsContent,     #[serde(flatten)]    pub workspace: WorkspaceSettingsContent,     #[serde(flatten)]    pub editor: EditorSettingsContent,     #[serde(flatten)]    pub remote: RemoteSettingsContent,     /// Settings related to the file finder.    pub file_finder: Option<FileFinderSettingsContent>,     pub git_panel: Option<GitPanelSettingsContent>,     pub tabs: Option<ItemSettingsContent>,    pub tab_bar: Option<TabBarSettingsContent>,    pub status_bar: Option<StatusBarSettingsContent>,     pub preview_tabs: Option<PreviewTabsSettingsContent>,     pub agent: Option<AgentSettingsContent>,    pub agent_servers: Option<AllAgentServersSettings>,     /// Configuration of audio in Zed.    pub audio: Option<AudioSettingsContent>,     /// Whether or not to automatically check for updates.    ///    /// Default: true    pub auto_update: Option<bool>,     /// This base keymap settings adjusts the default keybindings in Zed to be similar    /// to other common code editors. By default, Zed's keymap closely follows VSCode's    /// keymap, with minor adjustments, this corresponds to the "VSCode" setting.    ///    /// Default: VSCode    pub base_keymap: Option<BaseKeymapContent>,     /// Configuration for the collab panel visual settings.    pub collaboration_panel: Option<PanelSettingsContent>,     pub debugger: Option<DebuggerSettingsContent>,     /// Configuration for Diagnostics-related features.    pub diagnostics: Option<DiagnosticsSettingsContent>,     /// Configuration for Git-related features    pub git: Option<GitSettings>,     /// Common language server settings.    pub global_lsp_settings: Option<GlobalLspSettingsContent>,     /// The settings for the image viewer.    pub image_viewer: Option<ImageViewerSettingsContent>,     pub repl: Option<ReplSettingsContent>,     /// Whether or not to enable Helix mode.    ///    /// Default: false    pub helix_mode: Option<bool>,     pub journal: Option<JournalSettingsContent>,     /// A map of log scopes to the desired log level.    /// Useful for filtering out noisy logs or enabling more verbose logging.    ///    /// Example: {"log": {"client": "warn"}}    pub log: Option<HashMap<String, String>>,     pub line_indicator_format: Option<LineIndicatorFormat>,     pub language_models: Option<AllLanguageModelSettingsContent>,     pub outline_panel: Option<OutlinePanelSettingsContent>,     pub project_panel: Option<ProjectPanelSettingsContent>,     /// Configuration for the Message Editor    pub message_editor: Option<MessageEditorSettings>,     /// Configuration for Node-related features    pub node: Option<NodeBinarySettings>,     /// Configuration for the Notification Panel    pub notification_panel: Option<NotificationPanelSettingsContent>,     pub proxy: Option<String>,     /// The URL of the Zed server to connect to.    pub server_url: Option<String>,     /// Configuration for session-related features    pub session: Option<SessionSettingsContent>,    /// Control what info is collected by Zed.    pub telemetry: Option<TelemetrySettingsContent>,     /// Configuration of the terminal in Zed.    pub terminal: Option<TerminalSettingsContent>,     pub title_bar: Option<TitleBarSettingsContent>,     /// Whether or not to enable Vim mode.    ///    /// Default: false    pub vim_mode: Option<bool>,     // Settings related to calls in Zed    pub calls: Option<CallSettingsContent>,     /// Settings for the which-key popup.    pub which_key: Option<WhichKeySettingsContent>,     /// Settings related to Vim mode in Zed.    pub vim: Option<VimSettingsContent>,} impl SettingsContent {    pub fn languages_mut(&mut self) -> &mut HashMap<String, LanguageSettingsContent> {        &mut self.project.all_languages.languages.0    }} // These impls are there to optimize builds by avoiding monomorphization downstream. Yes, they're repetitive, but using default impls// break the optimization, for whatever reason.pub trait RootUserSettings: Sized + DeserializeOwned {    fn parse_json(json: &str) -> (Option<Self>, ParseStatus);    fn parse_json_with_comments(json: &str) -> anyhow::Result<Self>;} impl RootUserSettings for SettingsContent {    fn parse_json(json: &str) -> (Option<Self>, ParseStatus) {        fallible_options::parse_json(json)    }    fn parse_json_with_comments(json: &str) -> anyhow::Result<Self> {        parse_json_with_comments(json)    }}// Explicit opt-in instead of blanket impl to avoid monomorphizing downstream. Just a hunch though.impl RootUserSettings for Option<SettingsContent> {    fn parse_json(json: &str) -> (Option<Self>, ParseStatus) {        fallible_options::parse_json(json)    }    fn parse_json_with_comments(json: &str) -> anyhow::Result<Self> {        parse_json_with_comments(json)    }}impl RootUserSettings for UserSettingsContent {    fn parse_json(json: &str) -> (Option<Self>, ParseStatus) {        fallible_options::parse_json(json)    }    fn parse_json_with_comments(json: &str) -> anyhow::Result<Self> {        parse_json_with_comments(json)    }} settings_overrides! {    #[with_fallible_options]    #[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]    pub struct ReleaseChannelOverrides { dev, nightly, preview, stable }} settings_overrides! {    #[with_fallible_options]    #[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]    pub struct PlatformOverrides { macos, linux, windows }} #[with_fallible_options]#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct UserSettingsContent {    #[serde(flatten)]    pub content: Box<SettingsContent>,     #[serde(flatten)]    pub release_channel_overrides: ReleaseChannelOverrides,     #[serde(flatten)]    pub platform_overrides: PlatformOverrides,     #[serde(default)]    pub profiles: IndexMap<String, SettingsContent>,} pub struct ExtensionsSettingsContent {    pub all_languages: AllLanguageSettingsContent,} /// Base key bindings scheme. Base keymaps can be overridden with user keymaps.////// Default: VSCode#[derive(    Copy,    Clone,    Debug,    Serialize,    Deserialize,    JsonSchema,    MergeFrom,    PartialEq,    Eq,    Default,    strum::VariantArray,)]pub enum BaseKeymapContent {    #[default]    VSCode,    JetBrains,    SublimeText,    Atom,    TextMate,    Emacs,    Cursor,    None,} impl strum::VariantNames for BaseKeymapContent {    const VARIANTS: &'static [&'static str] = &[        "VSCode",        "JetBrains",        "Sublime Text",        "Atom",        "TextMate",        "Emacs",        "Cursor",        "None",    ];} #[with_fallible_options]#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]pub struct TitleBarSettingsContent {    /// Whether to show the branch icon beside branch switcher in the title bar.    ///    /// Default: false    pub show_branch_icon: Option<bool>,    /// Whether to show onboarding banners in the title bar.    ///    /// Default: true    pub show_onboarding_banner: Option<bool>,    /// Whether to show user avatar in the title bar.    ///    /// Default: true    pub show_user_picture: Option<bool>,    /// Whether to show the branch name button in the titlebar.    ///    /// Default: true    pub show_branch_name: Option<bool>,    /// Whether to show the project host and name in the titlebar.    ///    /// Default: true    pub show_project_items: Option<bool>,    /// Whether to show the sign in button in the title bar.    ///    /// Default: true    pub show_sign_in: Option<bool>,    /// Whether to show the user menu button in the title bar.    ///    /// Default: true    pub show_user_menu: Option<bool>,    /// Whether to show the menus in the title bar.    ///    /// Default: false    pub show_menus: Option<bool>,} /// Configuration of audio in Zed.#[with_fallible_options]#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]pub struct AudioSettingsContent {    /// Opt into the new audio system.    ///    /// You need to rejoin a call for this setting to apply    #[serde(rename = "experimental.rodio_audio")]    pub rodio_audio: Option<bool>, // default is false    /// Requires 'rodio_audio: true'    ///    /// Automatically increase or decrease you microphone's volume. This affects how    /// loud you sound to others.    ///    /// Recommended: off (default)    /// Microphones are too quite in zed, until everyone is on experimental    /// audio and has auto speaker volume on this will make you very loud    /// compared to other speakers.    #[serde(rename = "experimental.auto_microphone_volume")]    pub auto_microphone_volume: Option<bool>,    /// Requires 'rodio_audio: true'    ///    /// Automatically increate or decrease the volume of other call members.    /// This only affects how things sound for you.    #[serde(rename = "experimental.auto_speaker_volume")]    pub auto_speaker_volume: Option<bool>,    /// Requires 'rodio_audio: true'    ///    /// Remove background noises. Works great for typing, cars, dogs, AC. Does    /// not work well on music.    #[serde(rename = "experimental.denoise")]    pub denoise: Option<bool>,    /// Requires 'rodio_audio: true'    ///    /// Use audio parameters compatible with the previous versions of    /// experimental audio and non-experimental audio. When this is false you    /// will sound strange to anyone not on the latest experimental audio. In    /// the future we will migrate by setting this to false    ///    /// You need to rejoin a call for this setting to apply    #[serde(rename = "experimental.legacy_audio_compatible")]    pub legacy_audio_compatible: Option<bool>,    /// Requires 'rodio_audio: true'    ///    /// Select specific output audio device.    #[serde(rename = "experimental.output_audio_device")]    pub output_audio_device: Option<AudioOutputDeviceName>,    /// Requires 'rodio_audio: true'    ///    /// Select specific input audio device.    #[serde(rename = "experimental.input_audio_device")]    pub input_audio_device: Option<AudioInputDeviceName>,} #[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]#[serde(transparent)]pub struct AudioOutputDeviceName(pub Option<String>); impl AsRef<Option<String>> for AudioInputDeviceName {    fn as_ref(&self) -> &Option<String> {        &self.0    }} impl From<Option<String>> for AudioInputDeviceName {    fn from(value: Option<String>) -> Self {        Self(value)    }} #[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]#[serde(transparent)]pub struct AudioInputDeviceName(pub Option<String>); impl AsRef<Option<String>> for AudioOutputDeviceName {    fn as_ref(&self) -> &Option<String> {        &self.0    }} impl From<Option<String>> for AudioOutputDeviceName {    fn from(value: Option<String>) -> Self {        Self(value)    }} /// Control what info is collected by Zed.#[with_fallible_options]#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Debug, MergeFrom)]pub struct TelemetrySettingsContent {    /// Send debug info like crash reports.    ///    /// Default: true    pub diagnostics: Option<bool>,    /// Send anonymized usage data like what languages you're using Zed with.    ///    /// Default: true    pub metrics: Option<bool>,} impl Default for TelemetrySettingsContent {    fn default() -> Self {        Self {            diagnostics: Some(true),            metrics: Some(true),        }    }} #[with_fallible_options]#[derive(Default, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Clone, MergeFrom)]pub struct DebuggerSettingsContent {    /// Determines the stepping granularity.    ///    /// Default: line    pub stepping_granularity: Option<SteppingGranularity>,    /// Whether the breakpoints should be reused across Zed sessions.    ///    /// Default: true    pub save_breakpoints: Option<bool>,    /// Whether to show the debug button in the status bar.    ///    /// Default: true    pub button: Option<bool>,    /// Time in milliseconds until timeout error when connecting to a TCP debug adapter    ///    /// Default: 2000ms    pub timeout: Option<u64>,    /// Whether to log messages between active debug adapters and Zed    ///    /// Default: true    pub log_dap_communications: Option<bool>,    /// Whether to format dap messages in when adding them to debug adapter logger    ///    /// Default: true    pub format_dap_log_messages: Option<bool>,    /// The dock position of the debug panel    ///    /// Default: Bottom    pub dock: Option<DockPosition>,} /// The granularity of one 'step' in the stepping requests `next`, `stepIn`, `stepOut`, and `stepBack`.#[derive(    PartialEq,

Lines 1–500 of 1271.