Fix server settings (#38477)

In the settings refactor I'd assumed server settings were like project
settings. This is not the case, they are in fact the normal user
settings;
but just read from the server.

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin
2025-09-19 10:38:39 -06:00
committed by GitHub
parent b9188e0fd3
commit 30a29ab34e
7 changed files with 13 additions and 60 deletions
Generated
+1
View File
@@ -5295,6 +5295,7 @@ dependencies = [
"url", "url",
"util", "util",
"uuid", "uuid",
"vim_mode_setting",
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zed_actions", "zed_actions",
+1
View File
@@ -89,6 +89,7 @@ ui.workspace = true
url.workspace = true url.workspace = true
util.workspace = true util.workspace = true
uuid.workspace = true uuid.workspace = true
vim_mode_setting.workspace = true
workspace.workspace = true workspace.workspace = true
zed_actions.workspace = true zed_actions.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
+3 -5
View File
@@ -21678,12 +21678,10 @@ impl Editor {
} }
} }
// todo(settings_refactor) this should not be!
fn vim_enabled(cx: &App) -> bool { fn vim_enabled(cx: &App) -> bool {
cx.global::<SettingsStore>() vim_mode_setting::VimModeSetting::try_get(cx)
.raw_user_settings() .map(|vim_mode| vim_mode.0)
.and_then(|settings| settings.content.vim_mode) .unwrap_or(false)
== Some(true)
} }
fn process_completion_for_edit( fn process_completion_for_edit(
+1 -4
View File
@@ -770,12 +770,9 @@ impl SettingsObserver {
envelope: TypedEnvelope<proto::UpdateUserSettings>, envelope: TypedEnvelope<proto::UpdateUserSettings>,
cx: AsyncApp, cx: AsyncApp,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let new_settings = serde_json::from_str(&envelope.payload.contents).with_context(|| {
format!("deserializing {} user settings", envelope.payload.contents)
})?;
cx.update_global(|settings_store: &mut SettingsStore, cx| { cx.update_global(|settings_store: &mut SettingsStore, cx| {
settings_store settings_store
.set_raw_user_settings(new_settings, cx) .set_user_settings(&envelope.payload.contents, cx)
.context("setting new user settings")?; .context("setting new user settings")?;
anyhow::Ok(()) anyhow::Ok(())
})??; })??;
@@ -1797,8 +1797,8 @@ async fn test_remote_external_agent_server(
pretty_assertions::assert_eq!(names, ["gemini", "claude"]); pretty_assertions::assert_eq!(names, ["gemini", "claude"]);
server_cx.update_global::<SettingsStore, _>(|settings_store, cx| { server_cx.update_global::<SettingsStore, _>(|settings_store, cx| {
settings_store settings_store
.set_raw_server_settings( .set_server_settings(
Some(json!({ &json!({
"agent_servers": { "agent_servers": {
"foo": { "foo": {
"command": "foo-cli", "command": "foo-cli",
@@ -1808,7 +1808,8 @@ async fn test_remote_external_agent_server(
} }
} }
} }
})), })
.to_string(),
cx, cx,
) )
.unwrap(); .unwrap();
-7
View File
@@ -166,13 +166,6 @@ impl SettingsContent {
} }
} }
#[skip_serializing_none]
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
pub struct ServerSettingsContent {
#[serde(flatten)]
pub project: ProjectSettingsContent,
}
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)] #[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize, JsonSchema, MergeFrom)]
pub struct UserSettingsContent { pub struct UserSettingsContent {
+3 -41
View File
@@ -36,8 +36,7 @@ use crate::{
merge_from::MergeFrom, merge_from::MergeFrom,
parse_json_with_comments, replace_value_in_json_text, parse_json_with_comments, replace_value_in_json_text,
settings_content::{ settings_content::{
ExtensionsSettingsContent, ProjectSettingsContent, ServerSettingsContent, SettingsContent, ExtensionsSettingsContent, ProjectSettingsContent, SettingsContent, UserSettingsContent,
UserSettingsContent,
}, },
update_value_in_json_text, update_value_in_json_text,
}; };
@@ -327,33 +326,6 @@ impl SettingsStore {
self.user_settings.as_ref() self.user_settings.as_ref()
} }
/// Replaces current settings with the values from the given JSON.
pub fn set_raw_user_settings(
&mut self,
new_settings: UserSettingsContent,
cx: &mut App,
) -> Result<()> {
self.user_settings = Some(new_settings);
self.recompute_values(None, cx)?;
Ok(())
}
/// Replaces current settings with the values from the given JSON.
pub fn set_raw_server_settings(
&mut self,
new_settings: Option<Value>,
cx: &mut App,
) -> Result<()> {
// Rewrite the server settings into a content type
self.server_settings = new_settings
.map(|settings| settings.to_string())
.and_then(|str| parse_json_with_comments::<SettingsContent>(&str).ok())
.map(Box::new);
self.recompute_values(None, cx)?;
Ok(())
}
/// Get the configured settings profile names. /// Get the configured settings profile names.
pub fn configured_settings_profiles(&self) -> impl Iterator<Item = &str> { pub fn configured_settings_profiles(&self) -> impl Iterator<Item = &str> {
self.user_settings self.user_settings
@@ -361,11 +333,6 @@ impl SettingsStore {
.flat_map(|settings| settings.profiles.keys().map(|k| k.as_str())) .flat_map(|settings| settings.profiles.keys().map(|k| k.as_str()))
} }
/// Access the raw JSON value of the default settings.
pub fn raw_default_settings(&self) -> &SettingsContent {
&self.default_settings
}
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub fn test(cx: &mut App) -> Self { pub fn test(cx: &mut App) -> Self {
Self::new(cx, &crate::test_settings()) Self::new(cx, &crate::test_settings())
@@ -621,19 +588,14 @@ impl SettingsStore {
server_settings_content: &str, server_settings_content: &str,
cx: &mut App, cx: &mut App,
) -> Result<()> { ) -> Result<()> {
let settings: Option<ServerSettingsContent> = if server_settings_content.is_empty() { let settings: Option<SettingsContent> = if server_settings_content.is_empty() {
None None
} else { } else {
parse_json_with_comments(server_settings_content)? parse_json_with_comments(server_settings_content)?
}; };
// Rewrite the server settings into a content type // Rewrite the server settings into a content type
self.server_settings = settings.map(|settings| { self.server_settings = settings.map(|settings| Box::new(settings));
Box::new(SettingsContent {
project: settings.project,
..Default::default()
})
});
self.recompute_values(None, cx)?; self.recompute_values(None, cx)?;
Ok(()) Ok(())