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 /// Git blame settings.
260 pub blame: Option<BlameSettings>,
261 /// Which information to show in the branch picker.
262 ///
263 /// Default: on
264 pub branch_picker: Option<BranchPickerSettingsContent>,
265 /// How hunks are displayed visually in the editor.
266 ///
267 /// Default: staged_hollow
268 pub hunk_style: Option<GitHunkStyleSetting>,
269}
270
271#[derive(Clone, Copy, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
272#[serde(rename_all = "snake_case")]
273pub enum GitGutterSetting {
274 /// Show git gutter in tracked files.
275 #[default]
276 TrackedFiles,
277 /// Hide git gutter
278 Hide,
279}
280
281#[skip_serializing_none]
282#[derive(Clone, Copy, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
283#[serde(rename_all = "snake_case")]
284pub struct InlineBlameSettings {
285 /// Whether or not to show git blame data inline in
286 /// the currently focused line.
287 ///
288 /// Default: true
289 pub enabled: Option<bool>,
290 /// Whether to only show the inline blame information
291 /// after a delay once the cursor stops moving.
292 ///
293 /// Default: 0
294 pub delay_ms: Option<u64>,
295 /// The amount of padding between the end of the source line and the start
296 /// of the inline blame in units of columns.
297 ///
298 /// Default: 7
299 pub padding: Option<u32>,
300 /// The minimum column number to show the inline blame information at
301 ///
302 /// Default: 0
303 pub min_column: Option<u32>,
304 /// Whether to show commit summary as part of the inline blame.
305 ///
306 /// Default: false
307 pub show_commit_summary: Option<bool>,
308}
309
310#[skip_serializing_none]
311#[derive(Clone, Copy, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
312#[serde(rename_all = "snake_case")]
313pub struct BlameSettings {
314 /// Whether to show the avatar of the author of the commit.
315 ///
316 /// Default: true
317 pub show_avatar: Option<bool>,
318}
319
320#[skip_serializing_none]
321#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize, JsonSchema, MergeFrom)]
322#[serde(rename_all = "snake_case")]
323pub struct BranchPickerSettingsContent {
324 /// Whether to show author name as part of the commit information.
325 ///
326 /// Default: false
327 pub show_author_name: Option<bool>,
328}
329
330#[derive(Clone, Copy, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
331#[serde(rename_all = "snake_case")]
332pub enum GitHunkStyleSetting {
333 /// Show unstaged hunks with a filled background and staged hunks hollow.
334 #[default]
335 StagedHollow,
336 /// Show unstaged hunks hollow and staged hunks with a filled background.
337 UnstagedHollow,
338}
339
340#[skip_serializing_none]
341#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]
342pub struct DiagnosticsSettingsContent {
343 /// Whether to show the project diagnostics button in the status bar.
344 pub button: Option<bool>,
345
346 /// Whether or not to include warning diagnostics.
347 pub include_warnings: Option<bool>,
348
349 /// Settings for using LSP pull diagnostics mechanism in Zed.
350 pub lsp_pull_diagnostics: Option<LspPullDiagnosticsSettingsContent>,
351
352 /// Settings for showing inline diagnostics.
353 pub inline: Option<InlineDiagnosticsSettingsContent>,
354}
355
356#[skip_serializing_none]
357#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
358pub struct LspPullDiagnosticsSettingsContent {
359 /// Whether to pull for diagnostics or not.
360 ///
361 /// Default: true
362 pub enabled: Option<bool>,
363 /// Minimum time to wait before pulling diagnostics from the language server(s).
364 /// 0 turns the debounce off.
365 ///
366 /// Default: 50
367 pub debounce_ms: Option<u64>,
368}
369
370#[skip_serializing_none]
371#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom, Eq)]
372pub struct InlineDiagnosticsSettingsContent {
373 /// Whether or not to show inline diagnostics
374 ///
375 /// Default: false
376 pub enabled: Option<bool>,
377 /// Whether to only show the inline diagnostics after a delay after the
378 /// last editor event.
379 ///
380 /// Default: 150
381 pub update_debounce_ms: Option<u64>,
382 /// The amount of padding between the end of the source line and the start
383 /// of the inline diagnostic in units of columns.
384 ///
385 /// Default: 4
386 pub padding: Option<u32>,
387 /// The minimum column to display inline diagnostics. This setting can be
388 /// used to horizontally align inline diagnostics at some position. Lines
389 /// longer than this value will still push diagnostics further to the right.
390 ///
391 /// Default: 0
392 pub min_column: Option<u32>,
393
394 pub max_severity: Option<DiagnosticSeverityContent>,
395}
396
397#[skip_serializing_none]
398#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom)]
399pub struct NodeBinarySettings {
400 /// The path to the Node binary.
401 pub path: Option<String>,
402 /// The path to the npm binary Zed should use (defaults to `.path/../npm`).
403 pub npm_path: Option<String>,
404 /// If enabled, Zed will download its own copy of Node.
405 pub ignore_system_version: Option<bool>,
406}
407
408#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
409#[serde(rename_all = "snake_case")]
410pub enum DirenvSettings {
411 /// Load direnv configuration through a shell hook
412 ShellHook,
413 /// Load direnv configuration directly using `direnv export json`
414 #[default]
415 Direct,
416}
417
418#[derive(
419 Clone,
420 Copy,
421 Debug,
422 Eq,
423 PartialEq,
424 Ord,
425 PartialOrd,
426 Serialize,
427 Deserialize,
428 JsonSchema,
429 MergeFrom,
430)]
431#[serde(rename_all = "snake_case")]
432pub enum DiagnosticSeverityContent {
433 // No diagnostics are shown.
434 Off,
435 Error,
436 Warning,
437 Info,
438 #[serde(alias = "all")]
439 Hint,
440}
441
442/// A custom Git hosting provider.
443#[skip_serializing_none]
444#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]
445pub struct GitHostingProviderConfig {
446 /// The type of the provider.
447 ///
448 /// Must be one of `github`, `gitlab`, or `bitbucket`.
449 pub provider: GitHostingProviderKind,
450
451 /// The base URL for the provider (e.g., "https://code.corp.big.com").
452 pub base_url: String,
453
454 /// The display name for the provider (e.g., "BigCorp GitHub").
455 pub name: String,
456}
457
458#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
459#[serde(rename_all = "snake_case")]
460pub enum GitHostingProviderKind {
461 Github,
462 Gitlab,
463 Bitbucket,
464}