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: on
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: true
75 #[serde(default = "true_value")]
76 pub enabled: bool,
77 /// Whether to only show the inline blame information
78 /// after a delay once the cursor stops moving.
79 ///
80 /// Default: 0
81 pub delay_ms: Option<u64>,
82 /// The minimum column number to show the inline blame information at
83 ///
84 /// Default: 0
85 pub min_column: Option<u32>,
86}
87
88const fn true_value() -> bool {
89 true
90}
91
92#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
93pub struct BinarySettings {
94 pub path: Option<String>,
95 pub arguments: Option<Vec<String>>,
96}
97
98#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
99#[serde(rename_all = "snake_case")]
100pub struct LspSettings {
101 pub binary: Option<BinarySettings>,
102 pub initialization_options: Option<serde_json::Value>,
103 pub settings: Option<serde_json::Value>,
104}
105
106impl Settings for ProjectSettings {
107 const KEY: Option<&'static str> = None;
108
109 type FileContent = Self;
110
111 fn load(
112 sources: SettingsSources<Self::FileContent>,
113 _: &mut AppContext,
114 ) -> anyhow::Result<Self> {
115 sources.json_merge()
116 }
117}