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