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