project_settings.rs

 1use collections::HashMap;
 2use schemars::JsonSchema;
 3use serde::{Deserialize, Serialize};
 4use settings::Setting;
 5use std::sync::Arc;
 6
 7#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 8pub struct ProjectSettings {
 9    #[serde(default)]
10    pub lsp: HashMap<Arc<str>, LspSettings>,
11    #[serde(default)]
12    pub git: GitSettings,
13    // TODO kb better names and docs and tests
14    // TODO kb how to react on their changes?
15    #[serde(default)]
16    pub scan_exclude_files: Vec<String>,
17}
18
19#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
20pub struct GitSettings {
21    pub git_gutter: Option<GitGutterSetting>,
22    pub gutter_debounce: Option<u64>,
23}
24
25#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
26#[serde(rename_all = "snake_case")]
27pub enum GitGutterSetting {
28    #[default]
29    TrackedFiles,
30    Hide,
31}
32
33#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
34#[serde(rename_all = "snake_case")]
35pub struct LspSettings {
36    pub initialization_options: Option<serde_json::Value>,
37}
38
39impl Setting for ProjectSettings {
40    const KEY: Option<&'static str> = None;
41
42    type FileContent = Self;
43
44    fn load(
45        default_value: &Self::FileContent,
46        user_values: &[&Self::FileContent],
47        _: &gpui::AppContext,
48    ) -> anyhow::Result<Self> {
49        Self::load_via_json_merge(default_value, user_values)
50    }
51}