1207 lines · 42.4 KB · Rust
RawDownload
use anyhow::Context as _;use collections::HashMap;use context_server::ContextServerCommand;use dap::adapters::DebugAdapterName;use fs::Fs;use futures::StreamExt as _;use gpui::{App, AsyncApp, BorrowAppContext, Context, Entity, EventEmitter, Task};use lsp::LanguageServerName;use paths::{    EDITORCONFIG_NAME, local_debug_file_relative_path, local_settings_file_relative_path,    local_tasks_file_relative_path, local_vscode_launch_file_relative_path,    local_vscode_tasks_file_relative_path, task_file_name,};use rpc::{    AnyProtoClient, TypedEnvelope,    proto::{self, FromProto, ToProto},};use schemars::JsonSchema;use serde::{Deserialize, Serialize};use settings::{    InvalidSettingsError, LocalSettingsKind, Settings, SettingsLocation, SettingsSources,    SettingsStore, parse_json_with_comments, watch_config_file,};use std::{    path::{Path, PathBuf},    sync::Arc,    time::Duration,};use task::{DebugTaskFile, TaskTemplates, VsCodeDebugTaskFile, VsCodeTaskFile};use util::{ResultExt, serde::default_true};use worktree::{PathChange, UpdatedEntriesSet, Worktree, WorktreeId}; use crate::{    task_store::{TaskSettingsLocation, TaskStore},    worktree_store::{WorktreeStore, WorktreeStoreEvent},}; #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]pub struct ProjectSettings {    /// Configuration for language servers.    ///    /// The following settings can be overridden for specific language servers:    /// - initialization_options    ///    /// To override settings for a language, add an entry for that language server's    /// name to the lsp value.    /// Default: null    #[serde(default)]    pub lsp: HashMap<LanguageServerName, LspSettings>,     /// Common language server settings.    #[serde(default)]    pub global_lsp_settings: GlobalLspSettings,     /// Configuration for Debugger-related features    #[serde(default)]    pub dap: HashMap<DebugAdapterName, DapSettings>,     /// Settings for context servers used for AI-related features.    #[serde(default)]    pub context_servers: HashMap<Arc<str>, ContextServerSettings>,     /// Configuration for Diagnostics-related features.    #[serde(default)]    pub diagnostics: DiagnosticsSettings,     /// Configuration for Git-related features    #[serde(default)]    pub git: GitSettings,     /// Configuration for Node-related features    #[serde(default)]    pub node: NodeBinarySettings,     /// Configuration for how direnv configuration should be loaded    #[serde(default)]    pub load_direnv: DirenvSettings,     /// Configuration for session-related features    #[serde(default)]    pub session: SessionSettings,} #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub struct DapSettings {    pub binary: Option<String>,    #[serde(default)]    pub args: Vec<String>,} #[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, Debug)]#[serde(tag = "source", rename_all = "snake_case")]pub enum ContextServerSettings {    Custom {        /// Whether the context server is enabled.        #[serde(default = "default_true")]        enabled: bool,         #[serde(flatten)]        command: ContextServerCommand,    },    Extension {        /// Whether the context server is enabled.        #[serde(default = "default_true")]        enabled: bool,        /// The settings for this context server specified by the extension.        ///        /// Consult the documentation for the context server to see what settings        /// are supported.        settings: serde_json::Value,    },} /// Common language server settings.#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]pub struct GlobalLspSettings {    /// Whether to show the LSP servers button in the status bar.    ///    /// Default: `true`    #[serde(default = "default_true")]    pub button: bool,} impl ContextServerSettings {    pub fn default_extension() -> Self {        Self::Extension {            enabled: true,            settings: serde_json::json!({}),        }    }     pub fn enabled(&self) -> bool {        match self {            ContextServerSettings::Custom { enabled, .. } => *enabled,            ContextServerSettings::Extension { enabled, .. } => *enabled,        }    }     pub fn set_enabled(&mut self, enabled: bool) {        match self {            ContextServerSettings::Custom { enabled: e, .. } => *e = enabled,            ContextServerSettings::Extension { enabled: e, .. } => *e = enabled,        }    }} #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]pub struct NodeBinarySettings {    /// The path to the Node binary.    pub path: Option<String>,    /// The path to the npm binary Zed should use (defaults to `.path/../npm`).    pub npm_path: Option<String>,    /// If enabled, Zed will download its own copy of Node.    #[serde(default)]    pub ignore_system_version: bool,} #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum DirenvSettings {    /// Load direnv configuration through a shell hook    ShellHook,    /// Load direnv configuration directly using `direnv export json`    #[default]    Direct,} #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct DiagnosticsSettings {    /// Whether to show the project diagnostics button in the status bar.    pub button: bool,     /// Whether or not to include warning diagnostics.    pub include_warnings: bool,     /// Settings for using LSP pull diagnostics mechanism in Zed.    pub lsp_pull_diagnostics: LspPullDiagnosticsSettings,     /// Settings for showing inline diagnostics.    pub inline: InlineDiagnosticsSettings,     /// Configuration, related to Rust language diagnostics.    pub cargo: Option<CargoDiagnosticsSettings>,} impl DiagnosticsSettings {    pub fn fetch_cargo_diagnostics(&self) -> bool {        self.cargo.as_ref().map_or(false, |cargo_diagnostics| {            cargo_diagnostics.fetch_cargo_diagnostics        })    }} #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct LspPullDiagnosticsSettings {    /// Whether to pull for diagnostics or not.    ///    /// Default: true    #[serde(default = "default_true")]    pub enabled: bool,    /// Minimum time to wait before pulling diagnostics from the language server(s).    /// 0 turns the debounce off.    ///    /// Default: 50    #[serde(default = "default_lsp_diagnostics_pull_debounce_ms")]    pub debounce_ms: u64,} fn default_lsp_diagnostics_pull_debounce_ms() -> u64 {    50} #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct InlineDiagnosticsSettings {    /// Whether or not to show inline diagnostics    ///    /// Default: false    pub enabled: bool,    /// Whether to only show the inline diagnostics after a delay after the    /// last editor event.    ///    /// Default: 150    #[serde(default = "default_inline_diagnostics_update_debounce_ms")]    pub update_debounce_ms: u64,    /// The amount of padding between the end of the source line and the start    /// of the inline diagnostic in units of columns.    ///    /// Default: 4    #[serde(default = "default_inline_diagnostics_padding")]    pub padding: u32,    /// The minimum column to display inline diagnostics. This setting can be    /// used to horizontally align inline diagnostics at some position. Lines    /// longer than this value will still push diagnostics further to the right.    ///    /// Default: 0    pub min_column: u32,     pub max_severity: Option<DiagnosticSeverity>,} fn default_inline_diagnostics_update_debounce_ms() -> u64 {    150} fn default_inline_diagnostics_padding() -> u32 {    4} impl Default for DiagnosticsSettings {    fn default() -> Self {        Self {            button: true,            include_warnings: true,            lsp_pull_diagnostics: LspPullDiagnosticsSettings::default(),            inline: InlineDiagnosticsSettings::default(),            cargo: None,        }    }} impl Default for LspPullDiagnosticsSettings {    fn default() -> Self {        Self {            enabled: true,            debounce_ms: default_lsp_diagnostics_pull_debounce_ms(),        }    }} impl Default for InlineDiagnosticsSettings {    fn default() -> Self {        Self {            enabled: false,            update_debounce_ms: default_inline_diagnostics_update_debounce_ms(),            padding: default_inline_diagnostics_padding(),            min_column: 0,            max_severity: None,        }    }} impl Default for GlobalLspSettings {    fn default() -> Self {        Self {            button: default_true(),        }    }} #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]pub struct CargoDiagnosticsSettings {    /// When enabled, Zed disables rust-analyzer's check on save and starts to query    /// Cargo diagnostics separately.    ///    /// Default: false    #[serde(default)]    pub fetch_cargo_diagnostics: bool,} #[derive(    Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema,)]#[serde(rename_all = "snake_case")]pub enum DiagnosticSeverity {    // No diagnostics are shown.    Off,    Error,    Warning,    Info,    Hint,} impl DiagnosticSeverity {    pub fn into_lsp(self) -> Option<lsp::DiagnosticSeverity> {        match self {            DiagnosticSeverity::Off => None,            DiagnosticSeverity::Error => Some(lsp::DiagnosticSeverity::ERROR),            DiagnosticSeverity::Warning => Some(lsp::DiagnosticSeverity::WARNING),            DiagnosticSeverity::Info => Some(lsp::DiagnosticSeverity::INFORMATION),            DiagnosticSeverity::Hint => Some(lsp::DiagnosticSeverity::HINT),        }    }} /// Determines the severity of the diagnostic that should be moved to.#[derive(PartialEq, PartialOrd, Clone, Copy, Debug, Eq, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum GoToDiagnosticSeverity {    /// Errors    Error = 3,    /// Warnings    Warning = 2,    /// Information    Information = 1,    /// Hints    Hint = 0,} impl From<lsp::DiagnosticSeverity> for GoToDiagnosticSeverity {    fn from(severity: lsp::DiagnosticSeverity) -> Self {        match severity {            lsp::DiagnosticSeverity::ERROR => Self::Error,            lsp::DiagnosticSeverity::WARNING => Self::Warning,            lsp::DiagnosticSeverity::INFORMATION => Self::Information,            lsp::DiagnosticSeverity::HINT => Self::Hint,            _ => Self::Error,        }    }} impl GoToDiagnosticSeverity {    pub fn min() -> Self {        Self::Hint    }     pub fn max() -> Self {        Self::Error    }} /// Allows filtering diagnostics that should be moved to.#[derive(PartialEq, Clone, Copy, Debug, Deserialize, JsonSchema)]#[serde(untagged)]pub enum GoToDiagnosticSeverityFilter {    /// Move to diagnostics of a specific severity.    Only(GoToDiagnosticSeverity),     /// Specify a range of severities to include.    Range {        /// Minimum severity to move to. Defaults no "error".        #[serde(default = "GoToDiagnosticSeverity::min")]        min: GoToDiagnosticSeverity,        /// Maximum severity to move to. Defaults to "hint".        #[serde(default = "GoToDiagnosticSeverity::max")]        max: GoToDiagnosticSeverity,    },} impl Default for GoToDiagnosticSeverityFilter {    fn default() -> Self {        Self::Range {            min: GoToDiagnosticSeverity::min(),            max: GoToDiagnosticSeverity::max(),        }    }} impl GoToDiagnosticSeverityFilter {    pub fn matches(&self, severity: lsp::DiagnosticSeverity) -> bool {        let severity: GoToDiagnosticSeverity = severity.into();        match self {            Self::Only(target) => *target == severity,            Self::Range { min, max } => severity >= *min && severity <= *max,        }    }} #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]pub struct GitSettings {    /// Whether or not to show the git gutter.    ///    /// Default: tracked_files    pub git_gutter: Option<GitGutterSetting>,    /// Sets the debounce threshold (in milliseconds) after which changes are reflected in the git gutter.    ///    /// Default: null    pub gutter_debounce: Option<u64>,    /// Whether or not to show git blame data inline in    /// the currently focused line.    ///    /// Default: on    pub inline_blame: Option<InlineBlameSettings>,    /// How hunks are displayed visually in the editor.    ///    /// Default: staged_hollow    pub hunk_style: Option<GitHunkStyleSetting>,} impl GitSettings {    pub fn inline_blame_enabled(&self) -> bool {        #[allow(unknown_lints, clippy::manual_unwrap_or_default)]        match self.inline_blame {            Some(InlineBlameSettings { enabled, .. }) => enabled,            _ => false,        }    }     pub fn inline_blame_delay(&self) -> Option<Duration> {        match self.inline_blame {            Some(InlineBlameSettings {                delay_ms: Some(delay_ms),                ..            }) if delay_ms > 0 => Some(Duration::from_millis(delay_ms)),            _ => None,        }    }     pub fn show_inline_commit_summary(&self) -> bool {        match self.inline_blame {            Some(InlineBlameSettings {                show_commit_summary,                ..            }) => show_commit_summary,            _ => false,        }    }} #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum GitHunkStyleSetting {    /// Show unstaged hunks with a filled background and staged hunks hollow.    #[default]    StagedHollow,    /// Show unstaged hunks hollow and staged hunks with a filled background.    UnstagedHollow,} #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub enum GitGutterSetting {    /// Show git gutter in tracked files.    #[default]    TrackedFiles,    /// Hide git gutter    Hide,} #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub struct InlineBlameSettings {    /// Whether or not to show git blame data inline in    /// the currently focused line.    ///    /// Default: true    #[serde(default = "default_true")]    pub enabled: bool,    /// Whether to only show the inline blame information    /// after a delay once the cursor stops moving.    ///    /// Default: 0    pub delay_ms: Option<u64>,    /// The minimum column number to show the inline blame information at    ///    /// Default: 0    pub min_column: Option<u32>,    /// Whether to show commit summary as part of the inline blame.    ///    /// Default: false    #[serde(default)]    pub show_commit_summary: bool,} #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]pub struct BinarySettings {    pub path: Option<String>,

Lines 1–500 of 1207.