use collections::HashMap; use gpui::AppContext; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use settings::{Settings, SettingsSources}; use std::{sync::Arc, time::Duration}; #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] pub struct ProjectSettings { /// Configuration for language servers. /// /// The following settings can be overridden for specific language servers: /// - initialization_options /// To override settings for a language, add an entry for that language server's /// name to the lsp value. /// Default: null #[serde(default)] pub lsp: HashMap, LspSettings>, /// Configuration for Git-related features #[serde(default)] pub git: GitSettings, /// Configuration for how direnv configuration should be loaded #[serde(default)] pub load_direnv: DirenvSettings, } #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum DirenvSettings { /// Load direnv configuration through a shell hook #[default] ShellHook, /// Load direnv configuration directly using `direnv export json` /// /// Warning: This option is experimental and might cause some inconsistent behaviour compared to using the shell hook. /// If it does, please report it to GitHub Direct, } #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] pub struct GitSettings { /// Whether or not to show the git gutter. /// /// Default: tracked_files pub git_gutter: Option, pub gutter_debounce: Option, /// Whether or not to show git blame data inline in /// the currently focused line. /// /// Default: on pub inline_blame: Option, } impl GitSettings { pub fn inline_blame_enabled(&self) -> bool { #[allow(unknown_lints, clippy::manual_unwrap_or_default)] match self.inline_blame { Some(InlineBlameSettings { enabled, .. }) => enabled, _ => false, } } pub fn inline_blame_delay(&self) -> Option { match self.inline_blame { Some(InlineBlameSettings { delay_ms: Some(delay_ms), .. }) if delay_ms > 0 => Some(Duration::from_millis(delay_ms)), _ => None, } } } #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum GitGutterSetting { /// Show git gutter in tracked files. #[default] TrackedFiles, /// Hide git gutter Hide, } #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct InlineBlameSettings { /// Whether or not to show git blame data inline in /// the currently focused line. /// /// Default: true #[serde(default = "true_value")] pub enabled: bool, /// Whether to only show the inline blame information /// after a delay once the cursor stops moving. /// /// Default: 0 pub delay_ms: Option, /// The minimum column number to show the inline blame information at /// /// Default: 0 pub min_column: Option, } const fn true_value() -> bool { true } #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] pub struct BinarySettings { pub path: Option, pub arguments: Option>, pub path_lookup: Option, } #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct LspSettings { pub binary: Option, pub initialization_options: Option, pub settings: Option, } impl Settings for ProjectSettings { const KEY: Option<&'static str> = None; type FileContent = Self; fn load( sources: SettingsSources, _: &mut AppContext, ) -> anyhow::Result { sources.json_merge() } }