Skip to content

Commit

Permalink
Apply even more of clippy's fixes
Browse files Browse the repository at this point in the history
Expands #1759. I don't know why the PR didn't contain everything, but
here we go.
  • Loading branch information
MultisampledNight committed Feb 9, 2023
1 parent 29155b1 commit 3ff1b09
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 67 deletions.
4 changes: 2 additions & 2 deletions neovide-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::{parse_macro_input, Attribute, Data, DataStruct, DeriveInput, Error, Id
pub fn setting_group(item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as DeriveInput);
let prefix = setting_prefix(input.attrs.as_ref())
.map(|p| format!("{}_", p))
.map(|p| format!("{p}_"))
.unwrap_or_else(|| "".to_string());
stream(input, prefix)
}
Expand All @@ -27,7 +27,7 @@ fn stream(input: DeriveInput, prefix: String) -> TokenStream {
fn struct_stream(name: Ident, prefix: String, data: &DataStruct) -> TokenStream {
let fragments = data.fields.iter().map(|field| match field.ident {
Some(ref ident) => {
let vim_setting_name = format!("{}{}", prefix, ident);
let vim_setting_name = format!("{prefix}{ident}");
quote! {{
fn update_func(value: rmpv::Value) {
let mut s = crate::settings::SETTINGS.get::<#name>();
Expand Down
2 changes: 1 addition & 1 deletion src/bridge/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn create_platform_shell_command(command: &str, args: &[&str]) -> Option<StdComm
Some(result)
} else if cfg!(target_os = "macos") {
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
let mut result = StdCommand::new(&shell);
let mut result = StdCommand::new(shell);

result.arg("-c");
if env::var_os("TERM").is_none() {
Expand Down
26 changes: 13 additions & 13 deletions src/bridge/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ type Result<T> = std::result::Result<T, ParseError>;
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::Array(value) => write!(f, "invalid array format {}", value),
ParseError::Map(value) => write!(f, "invalid map format {}", value),
ParseError::String(value) => write!(f, "invalid string format {}", value),
ParseError::U64(value) => write!(f, "invalid u64 format {}", value),
ParseError::I64(value) => write!(f, "invalid i64 format {}", value),
ParseError::F64(value) => write!(f, "invalid f64 format {}", value),
ParseError::Bool(value) => write!(f, "invalid bool format {}", value),
ParseError::Array(value) => write!(f, "invalid array format {value}"),
ParseError::Map(value) => write!(f, "invalid map format {value}"),
ParseError::String(value) => write!(f, "invalid string format {value}"),
ParseError::U64(value) => write!(f, "invalid u64 format {value}"),
ParseError::I64(value) => write!(f, "invalid i64 format {value}"),
ParseError::F64(value) => write!(f, "invalid f64 format {value}"),
ParseError::Bool(value) => write!(f, "invalid bool format {value}"),
ParseError::WindowAnchor(value) => {
write!(f, "invalid window anchor format {}", value)
write!(f, "invalid window anchor format {value}")
}
ParseError::Format(debug_text) => {
write!(f, "invalid event format {}", debug_text)
write!(f, "invalid event format {debug_text}")
}
}
}
Expand Down Expand Up @@ -291,7 +291,7 @@ fn unpack_color(packed_color: u64) -> Color4f {

fn extract_values<const REQ: usize>(values: Vec<Value>) -> Result<[Value; REQ]> {
if REQ > values.len() {
Err(ParseError::Format(format!("{:?}", values)))
Err(ParseError::Format(format!("{values:?}")))
} else {
let mut required_values = vec![Value::Nil; REQ];

Expand All @@ -309,7 +309,7 @@ fn extract_values_with_optional<const REQ: usize, const OPT: usize>(
values: Vec<Value>,
) -> Result<([Value; REQ], [Option<Value>; OPT])> {
if REQ > values.len() {
Err(ParseError::Format(format!("{:?}", values)))
Err(ParseError::Format(format!("{values:?}")))
} else {
let mut required_values = vec![Value::Nil; REQ];
let mut optional_values = vec![None; OPT];
Expand Down Expand Up @@ -541,7 +541,7 @@ fn parse_grid_line_cell(grid_line_cell: Value) -> Result<GridLineCell> {
let text_value = cell_contents
.first_mut()
.map(take_value)
.ok_or_else(|| ParseError::Format(format!("{:?}", cell_contents)))?;
.ok_or_else(|| ParseError::Format(format!("{cell_contents:?}")))?;

let highlight_id = cell_contents
.get_mut(1)
Expand Down Expand Up @@ -835,7 +835,7 @@ pub fn parse_redraw_event(event_value: Value) -> Result<Vec<RedrawEvent>> {
let mut event_contents = parse_array(event_value)?.into_iter();
let event_name = event_contents
.next()
.ok_or_else(|| ParseError::Format(format!("{:?}", event_contents)))
.ok_or_else(|| ParseError::Format(format!("{event_contents:?}")))
.and_then(parse_string)?;

let events = event_contents;
Expand Down
3 changes: 1 addition & 2 deletions src/bridge/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ pub async fn setup_neovide_specific_state(nvim: &Neovim<TxWrapper>, is_remote: b

if let Err(command_error) = nvim.command("runtime! ginit.vim").await {
nvim.command(&format!(
"echomsg \"error encountered in ginit.vim {:?}\"",
command_error
"echomsg \"error encountered in ginit.vim {command_error:?}\""
))
.await
.ok();
Expand Down
2 changes: 1 addition & 1 deletion src/bridge/ui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl ParallelCommand {
.await
.expect("Focus Gained Failed"),
ParallelCommand::FileDrop(path) => {
nvim.command(format!("e {}", path).as_str()).await.ok();
nvim.command(format!("e {path}").as_str()).await.ok();
}
ParallelCommand::DisplayAvailableFonts(fonts) => {
let mut content: Vec<String> = vec![
Expand Down
8 changes: 3 additions & 5 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use clap::{builder::PossibleValue, ValueEnum};

// Options for the frame decorations
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Default)]
pub enum Frame {
#[default]
Full,
#[cfg(target_os = "macos")]
Transparent,
Expand All @@ -28,11 +30,7 @@ impl From<&'_ Frame> for &'static str {
}
}

impl Default for Frame {
fn default() -> Frame {
Frame::Full
}
}


impl ValueEnum for Frame {
fn value_variants<'a>() -> &'a [Self] {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn protected_main() {

//Will exit if -h or -v
if let Err(err) = cmd_line::handle_command_line_arguments(args().collect()) {
eprintln!("{}", err);
eprintln!("{err}");
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/cursor_renderer/cursor_vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl CursorVfx for ParticleTrail {
let travel_distance = travel.length();

// Increase amount of particles when cursor travels further
let particle_count = ((travel_distance / cursor_dimensions.y as f32).powf(1.5)
let particle_count = ((travel_distance / cursor_dimensions.y).powf(1.5)
* settings.vfx_particle_density
* 0.01) as usize;

Expand All @@ -262,7 +262,7 @@ impl CursorVfx for ParticleTrail {
TrailMode::Railgun => {
let phase = t / std::f32::consts::PI
* settings.vfx_particle_phase
* (travel_distance / cursor_dimensions.y as f32);
* (travel_distance / cursor_dimensions.y);
Point::new(phase.sin(), phase.cos()) * 2.0 * settings.vfx_particle_speed
}
TrailMode::Torpedo => {
Expand All @@ -285,7 +285,7 @@ impl CursorVfx for ParticleTrail {
TrailMode::PixieDust | TrailMode::Torpedo => {
prev_p
+ travel * self.rng.next_f32()
+ Point::new(0.0, cursor_dimensions.y as f32 * 0.5)
+ Point::new(0.0, cursor_dimensions.y * 0.5)
}
};

Expand Down
16 changes: 6 additions & 10 deletions src/renderer/fonts/font_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ fn parse_font_name(font_name: impl AsRef<str>) -> String {
}

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Default)]
pub enum FontEdging {
#[default]
AntiAlias,
SubpixelAntiAlias,
Alias,
Expand All @@ -117,14 +119,12 @@ impl FontEdging {
}
}

impl Default for FontEdging {
fn default() -> Self {
FontEdging::AntiAlias
}
}


#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Default)]
pub enum FontHinting {
#[default]
Full,
Normal,
Slight,
Expand All @@ -142,11 +142,7 @@ impl FontHinting {
}
}

impl Default for FontHinting {
fn default() -> Self {
FontHinting::Full
}
}


fn points_to_pixels(value: f32) -> f32 {
// Fonts in neovim are using points, not pixels.
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ impl Profiler {

// Show min, max, avg (average).
root_canvas.draw_str(
format!("min: {:.1}ms", min_ft),
format!("min: {min_ft:.1}ms"),
(rect.left, rect.bottom),
&self.font.skia_font,
&paint,
);
root_canvas.draw_str(
format!("avg: {:.1}ms", avg),
format!("avg: {avg:.1}ms"),
(rect.left, rect.bottom - graph_height * 0.5),
&self.font.skia_font,
&paint,
);
root_canvas.draw_str(
format!("max: {:.1}ms", max_ft),
format!("max: {max_ft:.1}ms"),
(rect.left, rect.bottom - graph_height),
&self.font.skia_font,
&paint,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/rendered_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl RenderedWindow {
root_canvas.draw_image_rect(
image,
None,
pixel_region.with_offset((0.0, scroll_offset as f32)),
pixel_region.with_offset((0.0, scroll_offset)),
&paint,
);
}
Expand All @@ -324,7 +324,7 @@ impl RenderedWindow {
root_canvas.draw_image_rect(
snapshot,
None,
pixel_region.with_offset((0.0, scroll_offset as f32)),
pixel_region.with_offset((0.0, scroll_offset)),
&paint,
);

Expand Down
32 changes: 16 additions & 16 deletions src/settings/from_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ mod tests {
let v3p = std::u64::MAX as f32;

v0.parse_from_value(v1);
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
v0.parse_from_value(v2);
assert_eq!(v0, v2p, "v0 should equal {} but is actually {}", v2p, v0);
assert_eq!(v0, v2p, "v0 should equal {v2p} but is actually {v0}");
v0.parse_from_value(v3);
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");

// This is a noop and prints an error
v0.parse_from_value(Value::from("asd"));
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");
}

#[test]
Expand All @@ -109,11 +109,11 @@ mod tests {
let v1p = std::u64::MAX;

v0.parse_from_value(v1);
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");

// This is a noop and prints an error
v0.parse_from_value(Value::from(-1));
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
}

#[test]
Expand All @@ -123,11 +123,11 @@ mod tests {
let v1p = std::u64::MAX as u32;

v0.parse_from_value(v1);
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");

// This is a noop and prints an error
v0.parse_from_value(Value::from(-1));
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
}

#[test]
Expand All @@ -137,11 +137,11 @@ mod tests {
let v1p = std::i64::MAX as i32;

v0.parse_from_value(v1);
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");

// This is a noop and prints an error
v0.parse_from_value(Value::from(-1));
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
}

#[test]
Expand All @@ -151,11 +151,11 @@ mod tests {
let v1p = "bar";

v0.parse_from_value(v1);
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");

// This is a noop and prints an error
v0.parse_from_value(Value::from(-1));
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
}

#[test]
Expand All @@ -169,14 +169,14 @@ mod tests {
let v3p = true;

v0.parse_from_value(v1);
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
v0.parse_from_value(v2);
assert_eq!(v0, v2p, "v0 should equal {} but is actually {}", v2p, v0);
assert_eq!(v0, v2p, "v0 should equal {v2p} but is actually {v0}");
v0.parse_from_value(v3);
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");

// This is a noop and prints an error
v0.parse_from_value(Value::from(-1));
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");
}
}
9 changes: 4 additions & 5 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Settings {
let keys: Vec<String> = self.listeners.read().keys().cloned().collect();

for name in keys {
let variable_name = format!("neovide_{}", name);
let variable_name = format!("neovide_{name}");
match nvim.get_var(&variable_name).await {
Ok(value) => {
self.listeners.read().get(&name).unwrap()(value);
Expand Down Expand Up @@ -119,8 +119,7 @@ impl Settings {
nvim.command(&vimscript)
.await
.unwrap_or_explained_panic(&format!(
"Could not setup setting notifier for {}",
name
"Could not setup setting notifier for {name}"
));
}
}
Expand Down Expand Up @@ -246,8 +245,8 @@ mod tests {
let v1: String = "foo".to_string();
let v2: String = "bar".to_string();
let v3: String = "baz".to_string();
let v4: String = format!("neovide_{}", v1);
let v5: String = format!("neovide_{}", v2);
let v4: String = format!("neovide_{v1}");
let v5: String = format!("neovide_{v2}");

//create_nvim_command tries to read from CmdLineSettings.neovim_args
//TODO: this sets a static variable. Can this have side effects on other tests?
Expand Down
5 changes: 2 additions & 3 deletions src/settings/window_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn settings_path() -> PathBuf {

fn load_settings() -> Result<PersistentSettings, String> {
let settings_path = settings_path();
let json = std::fs::read_to_string(&settings_path).map_err(|e| e.to_string())?;
let json = std::fs::read_to_string(settings_path).map_err(|e| e.to_string())?;
serde_json::from_str(&json).map_err(|e| e.to_string())
}

Expand Down Expand Up @@ -118,8 +118,7 @@ pub fn save_window_geometry(

pub fn parse_window_geometry(input: &str) -> Result<Dimensions, String> {
let invalid_parse_err = format!(
"Invalid geometry: {}\nValid format: <width>x<height>",
input
"Invalid geometry: {input}\nValid format: <width>x<height>"
);

input
Expand Down

0 comments on commit 3ff1b09

Please sign in to comment.