1use collections::HashMap;
2use gpui::AppContext;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use settings::{Settings, SettingsSources};
6use std::{sync::Arc, time::Duration};
7
8#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
9pub struct ProjectSettings {
10 /// Configuration for language servers.
11 ///
12 /// The following settings can be overridden for specific language servers:
13 /// - initialization_options
14 /// To override settings for a language, add an entry for that language server's
15 /// name to the lsp value.
16 /// Default: null
17 #[serde(default)]
18 pub lsp: HashMap<Arc<str>, LspSettings>,
19
20 /// Configuration for Git-related features
21 #[serde(default)]
22 pub git: GitSettings,
23}
24
25#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
26pub struct GitSettings {
27 /// Whether or not to show the git gutter.
28 ///
29 /// Default: tracked_files
30 pub git_gutter: Option<GitGutterSetting>,
31 pub gutter_debounce: Option<u64>,
32 /// Whether or not to show git blame data inline in
33 /// the currently focused line.
34 ///
35 /// Default: off
36 pub inline_blame: Option<InlineBlameSettings>,
37}
38
39impl GitSettings {
40 pub fn inline_blame_enabled(&self) -> bool {
41 match self.inline_blame {
42 Some(InlineBlameSettings { enabled, .. }) => enabled,
43 _ => false,
44 }
45 }
46
47 pub fn inline_blame_delay(&self) -> Option<Duration> {
48 match self.inline_blame {
49 Some(InlineBlameSettings {
50 delay_ms: Some(delay_ms),
51 ..
52 }) if delay_ms > 0 => Some(Duration::from_millis(delay_ms)),
53 _ => None,
54 }
55 }
56}
57
58#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
59#[serde(rename_all = "snake_case")]
60pub enum GitGutterSetting {
61 /// Show git gutter in tracked files.
62 #[default]
63 TrackedFiles,
64 /// Hide git gutter
65 Hide,
66}
67
68#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
69#[serde(rename_all = "snake_case")]
70pub struct InlineBlameSettings {
71 /// Whether or not to show git blame data inline in
72 /// the currently focused line.
73 ///
74 /// Default: false
75 pub enabled: bool,
76 /// Whether to only show the inline blame information
77 /// after a delay once the cursor stops moving.
78 ///
79 /// Default: 0
80 pub delay_ms: Option<u64>,
81}
82
83#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
84pub struct BinarySettings {
85 pub path: Option<String>,
86 pub arguments: Option<Vec<String>>,
87}
88
89#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
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}
96
97impl Settings for ProjectSettings {
98 const KEY: Option<&'static str> = None;
99
100 type FileContent = Self;
101
102 fn load(
103 sources: SettingsSources<Self::FileContent>,
104 _: &mut AppContext,
105 ) -> anyhow::Result<Self> {
106 sources.json_merge()
107 }
108}