settings_ui: Handle enums with fields (#37945)
Closes #ISSUE
Adds handling for Enums with fields (i.e. not `enum Foo { Yes, No }`) in
Settings UI. Accomplished by creating default values for each element
with fields (in the derive macro), and rendering a toggle button group
with a button for each variant where switching the active variant sets
the value in the settings JSON to the default for the new active
variant.
Release Notes:
- N/A *or* Added/Fixed/Improved ...
---------
Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
@@ -981,11 +981,17 @@ impl<'de> Deserialize<'de> for SelectedFormatter {
|
||||
}
|
||||
|
||||
/// Controls which formatters should be used when formatting code.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, SettingsUi)]
|
||||
#[serde(untagged)]
|
||||
pub enum FormatterList {
|
||||
Single(Formatter),
|
||||
Vec(Vec<Formatter>),
|
||||
Vec(#[settings_ui(skip)] Vec<Formatter>),
|
||||
}
|
||||
|
||||
impl Default for FormatterList {
|
||||
fn default() -> Self {
|
||||
Self::Single(Formatter::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[Formatter]> for FormatterList {
|
||||
@@ -998,22 +1004,28 @@ impl AsRef<[Formatter]> for FormatterList {
|
||||
}
|
||||
|
||||
/// Controls which formatter should be used when formatting code. If there are multiple formatters, they are executed in the order of declaration.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, SettingsUi)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Formatter {
|
||||
/// Format code using the current language server.
|
||||
LanguageServer { name: Option<String> },
|
||||
LanguageServer {
|
||||
#[settings_ui(skip)]
|
||||
name: Option<String>,
|
||||
},
|
||||
/// Format code using Zed's Prettier integration.
|
||||
#[default]
|
||||
Prettier,
|
||||
/// Format code using an external command.
|
||||
External {
|
||||
/// The external program to run.
|
||||
#[settings_ui(skip)]
|
||||
command: Arc<str>,
|
||||
/// The arguments to pass to the program.
|
||||
#[settings_ui(skip)]
|
||||
arguments: Option<Arc<[String]>>,
|
||||
},
|
||||
/// Files should be formatted using code actions executed by language servers.
|
||||
CodeActions(HashMap<String, bool>),
|
||||
CodeActions(#[settings_ui(skip)] HashMap<String, bool>),
|
||||
}
|
||||
|
||||
/// The settings for indent guides.
|
||||
|
||||
Reference in New Issue
Block a user