Add setting to allow disabling the Assistant (#9706)

This PR adds a new `assistant.enabled` setting that controls whether the
Zed Assistant is enabled.

Some users have requested the ability to disable the AI-related features
in Zed if they don't use them. Changing `assistant.enabled` to `false`
will hide the Assistant icon in the status bar (taking priority over the
`assistant.button` setting) as well as filter out the `assistant:`
actions.

The Assistant is enabled by default.

Release Notes:

- Added an `assistant.enabled` setting to control whether the Assistant
is enabled.
This commit is contained in:
Marshall Bowers 2024-03-22 11:55:29 -04:00 committed by GitHub
parent 4dc61f7ccd
commit c6d479715d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 100 additions and 37 deletions

View file

@ -160,6 +160,7 @@ fn open_ai_url() -> String {
#[derive(Default, Debug, Deserialize, Serialize)]
pub struct AssistantSettings {
pub enabled: bool,
pub button: bool,
pub dock: AssistantDockPosition,
pub default_width: Pixels,
@ -201,42 +202,26 @@ impl AssistantSettingsContent {
AssistantSettingsContent::Versioned(settings) => match settings {
VersionedAssistantSettingsContent::V1(settings) => settings.clone(),
},
AssistantSettingsContent::Legacy(settings) => {
if let Some(open_ai_api_url) = settings.openai_api_url.as_ref() {
AssistantSettingsContentV1 {
button: settings.button,
dock: settings.dock,
default_width: settings.default_width,
default_height: settings.default_height,
provider: Some(AssistantProvider::OpenAi {
default_model: settings
.default_open_ai_model
.clone()
.unwrap_or_default(),
api_url: open_ai_api_url.clone(),
}),
}
} else if let Some(open_ai_model) = settings.default_open_ai_model.clone() {
AssistantSettingsContentV1 {
button: settings.button,
dock: settings.dock,
default_width: settings.default_width,
default_height: settings.default_height,
provider: Some(AssistantProvider::OpenAi {
AssistantSettingsContent::Legacy(settings) => AssistantSettingsContentV1 {
enabled: None,
button: settings.button,
dock: settings.dock,
default_width: settings.default_width,
default_height: settings.default_height,
provider: if let Some(open_ai_api_url) = settings.openai_api_url.as_ref() {
Some(AssistantProvider::OpenAi {
default_model: settings.default_open_ai_model.clone().unwrap_or_default(),
api_url: open_ai_api_url.clone(),
})
} else {
settings.default_open_ai_model.clone().map(|open_ai_model| {
AssistantProvider::OpenAi {
default_model: open_ai_model,
api_url: open_ai_url(),
}),
}
} else {
AssistantSettingsContentV1 {
button: settings.button,
dock: settings.dock,
default_width: settings.default_width,
default_height: settings.default_height,
provider: None,
}
}
}
}
})
},
},
}
}
@ -264,6 +249,7 @@ pub enum VersionedAssistantSettingsContent {
impl Default for VersionedAssistantSettingsContent {
fn default() -> Self {
Self::V1(AssistantSettingsContentV1 {
enabled: None,
button: None,
dock: None,
default_width: None,
@ -275,6 +261,10 @@ impl Default for VersionedAssistantSettingsContent {
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug)]
pub struct AssistantSettingsContentV1 {
/// Whether the Assistant is enabled.
///
/// Default: true
enabled: Option<bool>,
/// Whether to show the assistant panel button in the status bar.
///
/// Default: true
@ -340,6 +330,7 @@ impl Settings for AssistantSettings {
for value in [default_value].iter().chain(user_values) {
let value = value.upgrade();
merge(&mut settings.enabled, value.enabled);
merge(&mut settings.button, value.button);
merge(&mut settings.dock, value.dock);
merge(