One big cleanup pass of clippy lints
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
e7540d2833
commit
8ba2f77148
138 changed files with 1328 additions and 1366 deletions
|
@ -49,37 +49,37 @@ impl KeymapFileContent {
|
|||
pub fn load(asset_path: &str, cx: &mut MutableAppContext) -> Result<()> {
|
||||
let content = Assets::get(asset_path).unwrap().data;
|
||||
let content_str = std::str::from_utf8(content.as_ref()).unwrap();
|
||||
Ok(parse_json_with_comments::<Self>(content_str)?.add(cx)?)
|
||||
parse_json_with_comments::<Self>(content_str)?.add_to_cx(cx)
|
||||
}
|
||||
|
||||
pub fn add(self, cx: &mut MutableAppContext) -> Result<()> {
|
||||
pub fn add_to_cx(self, cx: &mut MutableAppContext) -> Result<()> {
|
||||
for KeymapBlock { context, bindings } in self.0 {
|
||||
cx.add_bindings(
|
||||
bindings
|
||||
.into_iter()
|
||||
.map(|(keystroke, action)| {
|
||||
let action = action.0.get();
|
||||
let bindings = bindings
|
||||
.into_iter()
|
||||
.map(|(keystroke, action)| {
|
||||
let action = action.0.get();
|
||||
|
||||
// This is a workaround for a limitation in serde: serde-rs/json#497
|
||||
// We want to deserialize the action data as a `RawValue` so that we can
|
||||
// deserialize the action itself dynamically directly from the JSON
|
||||
// string. But `RawValue` currently does not work inside of an untagged enum.
|
||||
let action = if action.starts_with('[') {
|
||||
let ActionWithData(name, data) = serde_json::from_str(action)?;
|
||||
cx.deserialize_action(&name, Some(data.get()))
|
||||
} else {
|
||||
let name = serde_json::from_str(action)?;
|
||||
cx.deserialize_action(name, None)
|
||||
}
|
||||
.with_context(|| {
|
||||
format!(
|
||||
// This is a workaround for a limitation in serde: serde-rs/json#497
|
||||
// We want to deserialize the action data as a `RawValue` so that we can
|
||||
// deserialize the action itself dynamically directly from the JSON
|
||||
// string. But `RawValue` currently does not work inside of an untagged enum.
|
||||
let action = if action.starts_with('[') {
|
||||
let ActionWithData(name, data) = serde_json::from_str(action)?;
|
||||
cx.deserialize_action(&name, Some(data.get()))
|
||||
} else {
|
||||
let name = serde_json::from_str(action)?;
|
||||
cx.deserialize_action(name, None)
|
||||
}
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"invalid binding value for keystroke {keystroke}, context {context:?}"
|
||||
)
|
||||
})?;
|
||||
Binding::load(&keystroke, action, context.as_deref())
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?,
|
||||
)
|
||||
})?;
|
||||
Binding::load(&keystroke, action, context.as_deref())
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
cx.add_bindings(bindings);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ pub fn keymap_file_json_schema(action_names: &[&'static str]) -> serde_json::Val
|
|||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
||||
enum_values: Some(
|
||||
action_names
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|name| Value::String(name.to_string()))
|
||||
.collect(),
|
||||
),
|
||||
|
|
|
@ -200,7 +200,7 @@ impl Settings {
|
|||
}
|
||||
}
|
||||
if let Some(value) = &data.theme {
|
||||
if let Some(theme) = theme_registry.get(&value.to_string()).log_err() {
|
||||
if let Some(theme) = theme_registry.get(value).log_err() {
|
||||
self.theme = theme;
|
||||
}
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ impl Settings {
|
|||
language_overrides: Default::default(),
|
||||
lsp: Default::default(),
|
||||
projects_online_by_default: true,
|
||||
theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), || Default::default()),
|
||||
theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), Default::default),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ impl Settings {
|
|||
pub fn test_async(cx: &mut gpui::TestAppContext) {
|
||||
cx.update(|cx| {
|
||||
let settings = Self::test(cx);
|
||||
cx.set_global(settings.clone());
|
||||
cx.set_global(settings);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -327,12 +327,7 @@ pub fn settings_file_json_schema(
|
|||
// Create a schema for a theme name.
|
||||
let theme_name_schema = SchemaObject {
|
||||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
||||
enum_values: Some(
|
||||
theme_names
|
||||
.into_iter()
|
||||
.map(|name| Value::String(name))
|
||||
.collect(),
|
||||
),
|
||||
enum_values: Some(theme_names.into_iter().map(Value::String).collect()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue