1453 lines · 40.7 KB · Rust
RawDownload
mod action;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 title_bar;mod workspace; pub use action::{ActionName, ActionWithArguments, CommandAliasTarget};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 title_bar::*;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::{BTreeMap, BTreeSet};use std::hash::Hash;use std::sync::Arc;pub use util::serde::default_true; #[derive(Debug, Clone, PartialEq, Eq)]pub enum ParseStatus {    /// Settings were parsed successfully    Success,    /// Settings file was not changed, so no parsing was performed    Unchanged,    /// Settings failed to parse    Failed { error: String },} /// Determines when the mouse cursor should be hidden in response to keyboard/// input.////// Default: on_typing_and_action#[derive(    Copy,    Clone,    Debug,    Default,    Serialize,    Deserialize,    PartialEq,    Eq,    JsonSchema,    MergeFrom,    strum::VariantArray,    strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum HideMouseMode {    /// Never hide the mouse cursor    Never,    /// Hide only when typing    OnTyping,    /// Hide on typing and on key bindings that resolve to an action    #[default]    OnTypingAndAction,} /// Determines whether to reduce non-essential motion in the UI, such as/// loading spinners and pulsating labels, by rendering them in a static state.////// Default: off#[derive(    Copy,    Clone,    Debug,    Default,    Serialize,    Deserialize,    PartialEq,    Eq,    JsonSchema,    MergeFrom,    strum::VariantArray,    strum::VariantNames,)]#[serde(rename_all = "snake_case")]pub enum ReduceMotionMode {    /// Always reduce motion    On,    /// Never reduce motion    #[default]    Off,} #[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>,     /// The settings for the markdown preview.    pub markdown_preview: Option<MarkdownPreviewSettingsContent>,     pub repl: Option<ReplSettingsContent>,     /// Whether or not to enable Helix mode.    ///    /// Default: false    pub helix_mode: Option<bool>,     /// Determines when the mouse cursor should be hidden in response to    /// keyboard input. Applies globally across all input surfaces (editors,    /// terminals, palettes, etc.).    ///    /// Default: on_typing_and_action    pub hide_mouse: Option<HideMouseMode>,     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 Node-related features    pub node: Option<NodeBinarySettings>,     pub proxy: Option<String>,     /// Whether to reduce non-essential motion in the UI, such as loading    /// spinners and pulsating labels, by rendering them in a static state.    ///    /// Default: off    pub reduce_motion: Option<ReduceMotionMode>,     /// The URL of the Zed server to connect to.    pub server_url: Option<String>,     /// The URL used as the key for credential storage.    ///    /// When set, credentials are stored under this URL instead of `server_url`.    /// This allows running multiple Zed instances side by side without them    /// overwriting each other's keychain entries.    pub credentials_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>,     /// Number of lines to search for modelines at the beginning and end of files.    /// Modelines contain editor directives (e.g., vim/emacs settings) that configure    /// the editor behavior for specific files.    ///    /// Default: 5    pub modeline_lines: Option<usize>,     /// Local overrides for feature flags, keyed by flag name.    pub feature_flags: Option<FeatureFlagsMap>,     /// Settings for developer-oriented instrumentation tools (profilers,    /// tracers, etc.) that can be toggled at runtime.    pub instrumentation: Option<InstrumentationSettingsContent>,} /// Configuration for developer-oriented instrumentation tools that collect/// diagnostic data about a running Zed instance.#[with_fallible_options]#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct InstrumentationSettingsContent {    /// Configuration for the performance profiler, accessed via the    /// `zed: open performance profiler` action.    pub performance_profiler: Option<PerformanceProfilerSettingsContent>,} /// Configuration for the performance profiler which collects timing data/// for foreground and background executor tasks.#[with_fallible_options]#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct PerformanceProfilerSettingsContent {    /// Whether to collect timing data for foreground and background executor    /// tasks. Enabling this may lead to increased memory usage, hence it's    /// disabled by default for regular builds.    ///    /// Default: false    pub enabled: Option<bool>,} #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, MergeFrom)]#[serde(transparent)]pub struct FeatureFlagsMap(pub HashMap<String, String>); // A manual `JsonSchema` impl keeps this type's schema registered under a// unique name. The derived impl on a `#[serde(transparent)]` newtype around// `HashMap<String, String>` would inline to the map's own schema name (`Map_of_string`),// which is shared with every other `HashMap<String, String>` setting field in// `SettingsContent`. A named placeholder lets `json_schema_store` find and// replace just this field's schema at runtime without clobbering the others.impl JsonSchema for FeatureFlagsMap {    fn schema_name() -> std::borrow::Cow<'static, str> {        "FeatureFlagsMap".into()    }     fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {        schemars::json_schema!({            "type": "object",            "additionalProperties": { "type": "string" }        })    }} impl std::ops::Deref for FeatureFlagsMap {    type Target = HashMap<String, String>;    fn deref(&self) -> &Self::Target {        &self.0    }} impl std::ops::DerefMut for FeatureFlagsMap {    fn deref_mut(&mut self) -> &mut Self::Target {        &mut self.0    }} 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 }} /// Determines what settings a profile starts from before applying its overrides.#[derive(    Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom,)]#[serde(rename_all = "snake_case")]pub enum ProfileBase {    /// Apply profile settings on top of the user's current settings.    #[default]    User,    /// Apply profile settings on top of Zed's default settings, ignoring user customizations.    Default,} /// A named settings profile that can temporarily override settings.#[with_fallible_options]#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]pub struct SettingsProfile {    /// What base settings to start from before applying this profile's overrides.    ///    /// - `user`: Apply on top of user's settings (default)    /// - `default`: Apply on top of Zed's default settings, ignoring user customizations    #[serde(default)]    pub base: ProfileBase,     /// The settings overrides for this profile.    #[serde(default)]    pub settings: Box<SettingsContent>,} #[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, SettingsProfile>,} 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",    ];} 

Lines 1–500 of 1453.