slash_command_settings.rs

 1use gpui::App;
 2use settings::Settings;
 3use util::MergeFrom;
 4
 5/// Settings for slash commands.
 6#[derive(Debug, Default, Clone)]
 7pub struct SlashCommandSettings {
 8    /// Settings for the `/cargo-workspace` slash command.
 9    pub cargo_workspace: CargoWorkspaceCommandSettings,
10}
11
12/// Settings for the `/cargo-workspace` slash command.
13#[derive(Debug, Default, Clone)]
14pub struct CargoWorkspaceCommandSettings {
15    /// Whether `/cargo-workspace` is enabled.
16    pub enabled: bool,
17}
18
19// todo!() I think this setting is bogus... default.json has "slash_commands": {"project"}
20impl Settings for SlashCommandSettings {
21    fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
22        Self {
23            cargo_workspace: CargoWorkspaceCommandSettings {
24                enabled: content
25                    .project
26                    .slash_commands
27                    .clone()
28                    .unwrap()
29                    .cargo_workspace
30                    .unwrap()
31                    .enabled
32                    .unwrap(),
33            },
34        }
35    }
36
37    fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
38        let Some(slash_command) = content.project.slash_commands.as_ref() else {
39            return;
40        };
41        let Some(cargo_workspace) = slash_command.cargo_workspace.as_ref() else {
42            return;
43        };
44        self.cargo_workspace
45            .enabled
46            .merge_from(&cargo_workspace.enabled);
47    }
48}