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<Arc<str>, 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, /// Configuration for session-related features #[serde(default)] pub session: SessionSettings,} #[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 behavior 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<GitGutterSetting>, pub gutter_debounce: Option<u64>, /// Whether or not to show git blame data inline in /// the currently focused line. /// /// Default: on pub inline_blame: Option<InlineBlameSettings>,} 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<Duration> { 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<u64>, /// The minimum column number to show the inline blame information at /// /// Default: 0 pub min_column: Option<u32>,} const fn true_value() -> bool { true} #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]pub struct BinarySettings { pub path: Option<String>, pub arguments: Option<Vec<String>>, pub path_lookup: Option<bool>,} #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]#[serde(rename_all = "snake_case")]pub struct LspSettings { pub binary: Option<BinarySettings>, pub initialization_options: Option<serde_json::Value>, pub settings: Option<serde_json::Value>,} #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]pub struct SessionSettings { /// Whether or not to restore unsaved buffers on restart. /// /// If this is true, user won't be prompted whether to save/discard /// dirty files when closing the application. /// /// Default: true pub restore_unsaved_buffers: bool,} impl Default for SessionSettings { fn default() -> Self { Self { restore_unsaved_buffers: true, } }} impl Settings for ProjectSettings { const KEY: Option<&'static str> = None; type FileContent = Self; fn load( sources: SettingsSources<Self::FileContent>, _: &mut AppContext, ) -> anyhow::Result<Self> { sources.json_merge() }}
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<Arc<str>, 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,
/// Configuration for session-related features
#[serde(default)]
pub session: SessionSettings,
}
#[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 behavior 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<GitGutterSetting>,
pub gutter_debounce: Option<u64>,
/// Whether or not to show git blame data inline in
/// the currently focused line.
///
/// Default: on
pub inline_blame: Option<InlineBlameSettings>,
}
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<Duration> {
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<u64>,
/// The minimum column number to show the inline blame information at
///
/// Default: 0
pub min_column: Option<u32>,
}
const fn true_value() -> bool {
true
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
pub struct BinarySettings {
pub path: Option<String>,
pub arguments: Option<Vec<String>>,
pub path_lookup: Option<bool>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct LspSettings {
pub binary: Option<BinarySettings>,
pub initialization_options: Option<serde_json::Value>,
pub settings: Option<serde_json::Value>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct SessionSettings {
/// Whether or not to restore unsaved buffers on restart.
///
/// If this is true, user won't be prompted whether to save/discard
/// dirty files when closing the application.
///
/// Default: true
pub restore_unsaved_buffers: bool,
}
impl Default for SessionSettings {
fn default() -> Self {
Self {
restore_unsaved_buffers: true,
}
}
}
impl Settings for ProjectSettings {
const KEY: Option<&'static str> = None;
type FileContent = Self;
fn load(
sources: SettingsSources<Self::FileContent>,
_: &mut AppContext,
) -> anyhow::Result<Self> {
sources.json_merge()
}
}