slash_command_settings.rs

 1use anyhow::Result;
 2use gpui::App;
 3use schemars::JsonSchema;
 4use serde::{Deserialize, Serialize};
 5use settings::{Settings, SettingsSources};
 6
 7/// Settings for slash commands.
 8#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema)]
 9pub struct SlashCommandSettings {
10    /// Settings for the `/docs` slash command.
11    #[serde(default)]
12    pub docs: DocsCommandSettings,
13    /// Settings for the `/cargo-workspace` slash command.
14    #[serde(default)]
15    pub cargo_workspace: CargoWorkspaceCommandSettings,
16}
17
18/// Settings for the `/docs` slash command.
19#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema)]
20pub struct DocsCommandSettings {
21    /// Whether `/docs` is enabled.
22    #[serde(default)]
23    pub enabled: bool,
24}
25
26/// Settings for the `/cargo-workspace` slash command.
27#[derive(Deserialize, Serialize, Debug, Default, Clone, JsonSchema)]
28pub struct CargoWorkspaceCommandSettings {
29    /// Whether `/cargo-workspace` is enabled.
30    #[serde(default)]
31    pub enabled: bool,
32}
33
34impl Settings for SlashCommandSettings {
35    const KEY: Option<&'static str> = Some("slash_commands");
36
37    type FileContent = Self;
38
39    fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut App) -> Result<Self> {
40        SettingsSources::<Self::FileContent>::json_merge_with(
41            [sources.default]
42                .into_iter()
43                .chain(sources.user)
44                .chain(sources.server),
45        )
46    }
47
48    fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
49}