project_settings.rs

 1use collections::HashMap;
 2use gpui::AppContext;
 3use schemars::JsonSchema;
 4use serde::{Deserialize, Serialize};
 5use settings::Settings;
 6use std::sync::Arc;
 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}
33
34#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
35#[serde(rename_all = "snake_case")]
36pub enum GitGutterSetting {
37    /// Show git gutter in tracked files.
38    #[default]
39    TrackedFiles,
40    /// Hide git gutter
41    Hide,
42}
43
44#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
45pub struct BinarySettings {
46    pub path: Option<String>,
47    pub arguments: Option<Vec<String>>,
48}
49
50#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
51#[serde(rename_all = "snake_case")]
52pub struct LspSettings {
53    pub binary: Option<BinarySettings>,
54    pub initialization_options: Option<serde_json::Value>,
55    pub settings: Option<serde_json::Value>,
56}
57
58impl Settings for ProjectSettings {
59    const KEY: Option<&'static str> = None;
60
61    type FileContent = Self;
62
63    fn load(
64        default_value: &Self::FileContent,
65        user_values: &[&Self::FileContent],
66        _: &mut AppContext,
67    ) -> anyhow::Result<Self> {
68        Self::load_via_json_merge(default_value, user_values)
69    }
70}