project.rs

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