project.rs

  1use std::{path::PathBuf, sync::Arc};
  2
  3use collections::{BTreeMap, HashMap};
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6use serde_with::skip_serializing_none;
  7use settings_macros::MergeFrom;
  8use util::serde::default_true;
  9
 10use crate::{AllLanguageSettingsContent, ExtendingVec, SlashCommandSettings};
 11
 12#[skip_serializing_none]
 13#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
 14pub struct ProjectSettingsContent {
 15    #[serde(flatten)]
 16    pub all_languages: AllLanguageSettingsContent,
 17
 18    #[serde(flatten)]
 19    pub worktree: WorktreeSettingsContent,
 20
 21    /// Configuration for language servers.
 22    ///
 23    /// The following settings can be overridden for specific language servers:
 24    /// - initialization_options
 25    ///
 26    /// To override settings for a language, add an entry for that language server's
 27    /// name to the lsp value.
 28    /// Default: null
 29    #[serde(default)]
 30    pub lsp: HashMap<Arc<str>, LspSettings>,
 31
 32    /// Configuration for Debugger-related features
 33    #[serde(default)]
 34    pub dap: HashMap<Arc<str>, DapSettingsContent>,
 35
 36    /// Settings for context servers used for AI-related features.
 37    #[serde(default)]
 38    pub context_servers: HashMap<Arc<str>, ContextServerSettingsContent>,
 39
 40    /// Configuration for how direnv configuration should be loaded
 41    pub load_direnv: Option<DirenvSettings>,
 42
 43    /// Settings for slash commands.
 44    pub slash_commands: Option<SlashCommandSettings>,
 45
 46    /// The list of custom Git hosting providers.
 47    pub git_hosting_providers: Option<ExtendingVec<GitHostingProviderConfig>>,
 48}
 49
 50#[skip_serializing_none]
 51#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
 52pub struct WorktreeSettingsContent {
 53    /// The displayed name of this project. If not set, the root directory name
 54    /// will be displayed.
 55    ///
 56    /// Default: none
 57    pub project_name: Option<String>,
 58
 59    /// Completely ignore files matching globs from `file_scan_exclusions`. Overrides
 60    /// `file_scan_inclusions`.
 61    ///
 62    /// Default: [
 63    ///   "**/.git",
 64    ///   "**/.svn",
 65    ///   "**/.hg",
 66    ///   "**/.jj",
 67    ///   "**/CVS",
 68    ///   "**/.DS_Store",
 69    ///   "**/Thumbs.db",
 70    ///   "**/.classpath",
 71    ///   "**/.settings"
 72    /// ]
 73    pub file_scan_exclusions: Option<Vec<String>>,
 74
 75    /// Always include files that match these globs when scanning for files, even if they're
 76    /// ignored by git. This setting is overridden by `file_scan_exclusions`.
 77    /// Default: [
 78    ///  ".env*",
 79    ///  "docker-compose.*.yml",
 80    /// ]
 81    pub file_scan_inclusions: Option<Vec<String>>,
 82
 83    /// Treat the files matching these globs as `.env` files.
 84    /// Default: ["**/.env*", "**/*.pem", "**/*.key", "**/*.cert", "**/*.crt", "**/secrets.yml"]
 85    pub private_files: Option<ExtendingVec<String>>,
 86}
 87
 88#[skip_serializing_none]
 89#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, Hash)]
 90#[serde(rename_all = "snake_case")]
 91pub struct LspSettings {
 92    pub binary: Option<BinarySettings>,
 93    pub initialization_options: Option<serde_json::Value>,
 94    pub settings: Option<serde_json::Value>,
 95    /// If the server supports sending tasks over LSP extensions,
 96    /// this setting can be used to enable or disable them in Zed.
 97    /// Default: true
 98    #[serde(default = "default_true")]
 99    pub enable_lsp_tasks: bool,
100    pub fetch: Option<FetchSettings>,
101}
102
103impl Default for LspSettings {
104    fn default() -> Self {
105        Self {
106            binary: None,
107            initialization_options: None,
108            settings: None,
109            enable_lsp_tasks: true,
110            fetch: None,
111        }
112    }
113}
114
115#[skip_serializing_none]
116#[derive(
117    Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, Hash,
118)]
119pub struct BinarySettings {
120    pub path: Option<String>,
121    pub arguments: Option<Vec<String>>,
122    pub env: Option<BTreeMap<String, String>>,
123    pub ignore_system_version: Option<bool>,
124}
125
126#[skip_serializing_none]
127#[derive(
128    Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, Hash,
129)]
130pub struct FetchSettings {
131    // Whether to consider pre-releases for fetching
132    pub pre_release: Option<bool>,
133}
134
135/// Common language server settings.
136#[skip_serializing_none]
137#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]
138pub struct GlobalLspSettingsContent {
139    /// Whether to show the LSP servers button in the status bar.
140    ///
141    /// Default: `true`
142    pub button: Option<bool>,
143}
144
145#[skip_serializing_none]
146#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]
147#[serde(rename_all = "snake_case")]
148pub struct DapSettingsContent {
149    pub binary: Option<String>,
150    #[serde(default)]
151    pub args: Option<Vec<String>>,
152}
153
154#[skip_serializing_none]
155#[derive(
156    Default, Copy, Clone, PartialEq, Eq, Debug, Serialize, Deserialize, JsonSchema, MergeFrom,
157)]
158pub struct SessionSettingsContent {
159    /// Whether or not to restore unsaved buffers on restart.
160    ///
161    /// If this is true, user won't be prompted whether to save/discard
162    /// dirty files when closing the application.
163    ///
164    /// Default: true
165    pub restore_unsaved_buffers: Option<bool>,
166}
167
168#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, MergeFrom, Debug)]
169#[serde(tag = "source", rename_all = "snake_case")]
170pub enum ContextServerSettingsContent {
171    Custom {
172        /// Whether the context server is enabled.
173        #[serde(default = "default_true")]
174        enabled: bool,
175
176        #[serde(flatten)]
177        command: ContextServerCommand,
178    },
179    Extension {
180        /// Whether the context server is enabled.
181        #[serde(default = "default_true")]
182        enabled: bool,
183        /// The settings for this context server specified by the extension.
184        ///
185        /// Consult the documentation for the context server to see what settings
186        /// are supported.
187        settings: serde_json::Value,
188    },
189}
190impl ContextServerSettingsContent {
191    pub fn set_enabled(&mut self, enabled: bool) {
192        match self {
193            ContextServerSettingsContent::Custom {
194                enabled: custom_enabled,
195                command: _,
196            } => {
197                *custom_enabled = enabled;
198            }
199            ContextServerSettingsContent::Extension {
200                enabled: ext_enabled,
201                settings: _,
202            } => *ext_enabled = enabled,
203        }
204    }
205}
206
207#[skip_serializing_none]
208#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, MergeFrom)]
209pub struct ContextServerCommand {
210    #[serde(rename = "command")]
211    pub path: PathBuf,
212    pub args: Vec<String>,
213    pub env: Option<HashMap<String, String>>,
214    /// Timeout for tool calls in milliseconds. Defaults to 60000 (60 seconds) if not specified.
215    pub timeout: Option<u64>,
216}
217
218impl std::fmt::Debug for ContextServerCommand {
219    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
220        let filtered_env = self.env.as_ref().map(|env| {
221            env.iter()
222                .map(|(k, v)| {
223                    (
224                        k,
225                        if util::redact::should_redact(k) {
226                            "[REDACTED]"
227                        } else {
228                            v
229                        },
230                    )
231                })
232                .collect::<Vec<_>>()
233        });
234
235        f.debug_struct("ContextServerCommand")
236            .field("path", &self.path)
237            .field("args", &self.args)
238            .field("env", &filtered_env)
239            .finish()
240    }
241}
242
243#[skip_serializing_none]
244#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
245pub struct GitSettings {
246    /// Whether or not to show the git gutter.
247    ///
248    /// Default: tracked_files
249    pub git_gutter: Option<GitGutterSetting>,
250    /// Sets the debounce threshold (in milliseconds) after which changes are reflected in the git gutter.
251    ///
252    /// Default: null
253    pub gutter_debounce: Option<u64>,
254    /// Whether or not to show git blame data inline in
255    /// the currently focused line.
256    ///
257    /// Default: on
258    pub inline_blame: Option<InlineBlameSettings>,
259    /// Which information to show in the branch picker.
260    ///
261    /// Default: on
262    pub branch_picker: Option<BranchPickerSettingsContent>,
263    /// How hunks are displayed visually in the editor.
264    ///
265    /// Default: staged_hollow
266    pub hunk_style: Option<GitHunkStyleSetting>,
267}
268
269#[derive(Clone, Copy, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
270#[serde(rename_all = "snake_case")]
271pub enum GitGutterSetting {
272    /// Show git gutter in tracked files.
273    #[default]
274    TrackedFiles,
275    /// Hide git gutter
276    Hide,
277}
278
279#[skip_serializing_none]
280#[derive(Clone, Copy, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
281#[serde(rename_all = "snake_case")]
282pub struct InlineBlameSettings {
283    /// Whether or not to show git blame data inline in
284    /// the currently focused line.
285    ///
286    /// Default: true
287    pub enabled: Option<bool>,
288    /// Whether to only show the inline blame information
289    /// after a delay once the cursor stops moving.
290    ///
291    /// Default: 0
292    pub delay_ms: Option<u64>,
293    /// The amount of padding between the end of the source line and the start
294    /// of the inline blame in units of columns.
295    ///
296    /// Default: 7
297    pub padding: Option<u32>,
298    /// The minimum column number to show the inline blame information at
299    ///
300    /// Default: 0
301    pub min_column: Option<u32>,
302    /// Whether to show commit summary as part of the inline blame.
303    ///
304    /// Default: false
305    pub show_commit_summary: Option<bool>,
306}
307
308#[skip_serializing_none]
309#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize, JsonSchema, MergeFrom)]
310#[serde(rename_all = "snake_case")]
311pub struct BranchPickerSettingsContent {
312    /// Whether to show author name as part of the commit information.
313    ///
314    /// Default: false
315    pub show_author_name: Option<bool>,
316}
317
318#[derive(Clone, Copy, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
319#[serde(rename_all = "snake_case")]
320pub enum GitHunkStyleSetting {
321    /// Show unstaged hunks with a filled background and staged hunks hollow.
322    #[default]
323    StagedHollow,
324    /// Show unstaged hunks hollow and staged hunks with a filled background.
325    UnstagedHollow,
326}
327
328#[skip_serializing_none]
329#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]
330pub struct DiagnosticsSettingsContent {
331    /// Whether to show the project diagnostics button in the status bar.
332    pub button: Option<bool>,
333
334    /// Whether or not to include warning diagnostics.
335    pub include_warnings: Option<bool>,
336
337    /// Settings for using LSP pull diagnostics mechanism in Zed.
338    pub lsp_pull_diagnostics: Option<LspPullDiagnosticsSettingsContent>,
339
340    /// Settings for showing inline diagnostics.
341    pub inline: Option<InlineDiagnosticsSettingsContent>,
342}
343
344#[skip_serializing_none]
345#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
346pub struct LspPullDiagnosticsSettingsContent {
347    /// Whether to pull for diagnostics or not.
348    ///
349    /// Default: true
350    pub enabled: Option<bool>,
351    /// Minimum time to wait before pulling diagnostics from the language server(s).
352    /// 0 turns the debounce off.
353    ///
354    /// Default: 50
355    pub debounce_ms: Option<u64>,
356}
357
358#[skip_serializing_none]
359#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, Eq)]
360pub struct InlineDiagnosticsSettingsContent {
361    /// Whether or not to show inline diagnostics
362    ///
363    /// Default: false
364    pub enabled: Option<bool>,
365    /// Whether to only show the inline diagnostics after a delay after the
366    /// last editor event.
367    ///
368    /// Default: 150
369    pub update_debounce_ms: Option<u64>,
370    /// The amount of padding between the end of the source line and the start
371    /// of the inline diagnostic in units of columns.
372    ///
373    /// Default: 4
374    pub padding: Option<u32>,
375    /// The minimum column to display inline diagnostics. This setting can be
376    /// used to horizontally align inline diagnostics at some position. Lines
377    /// longer than this value will still push diagnostics further to the right.
378    ///
379    /// Default: 0
380    pub min_column: Option<u32>,
381
382    pub max_severity: Option<DiagnosticSeverityContent>,
383}
384
385#[skip_serializing_none]
386#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]
387pub struct NodeBinarySettings {
388    /// The path to the Node binary.
389    pub path: Option<String>,
390    /// The path to the npm binary Zed should use (defaults to `.path/../npm`).
391    pub npm_path: Option<String>,
392    /// If enabled, Zed will download its own copy of Node.
393    pub ignore_system_version: Option<bool>,
394}
395
396#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
397#[serde(rename_all = "snake_case")]
398pub enum DirenvSettings {
399    /// Load direnv configuration through a shell hook
400    ShellHook,
401    /// Load direnv configuration directly using `direnv export json`
402    #[default]
403    Direct,
404}
405
406#[derive(
407    Clone,
408    Copy,
409    Debug,
410    Eq,
411    PartialEq,
412    Ord,
413    PartialOrd,
414    Serialize,
415    Deserialize,
416    JsonSchema,
417    MergeFrom,
418)]
419#[serde(rename_all = "snake_case")]
420pub enum DiagnosticSeverityContent {
421    // No diagnostics are shown.
422    Off,
423    Error,
424    Warning,
425    Info,
426    #[serde(alias = "all")]
427    Hint,
428}
429
430/// A custom Git hosting provider.
431#[skip_serializing_none]
432#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]
433pub struct GitHostingProviderConfig {
434    /// The type of the provider.
435    ///
436    /// Must be one of `github`, `gitlab`, or `bitbucket`.
437    pub provider: GitHostingProviderKind,
438
439    /// The base URL for the provider (e.g., "https://code.corp.big.com").
440    pub base_url: String,
441
442    /// The display name for the provider (e.g., "BigCorp GitHub").
443    pub name: String,
444}
445
446#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
447#[serde(rename_all = "snake_case")]
448pub enum GitHostingProviderKind {
449    Github,
450    Gitlab,
451    Bitbucket,
452}