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