From a9acc532aa8cdc6adffb6ed0b48b3bdf00392518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Vald=C3=A9s?= Date: Wed, 5 Feb 2020 03:22:02 +0100 Subject: [PATCH] Fix a bunch of small issues reported by clippy --- src/bridge/handler.rs | 3 +-- src/bridge/mod.rs | 32 ++++++++++++++------------------ src/editor/cursor.rs | 14 +++++++------- src/editor/grid.rs | 6 +++--- src/editor/mod.rs | 12 ++++++------ src/editor/style.rs | 10 +++++----- src/main.rs | 9 +++++---- src/redraw_scheduler.rs | 4 ++-- src/renderer/caching_shaper.rs | 16 ++++++++-------- src/renderer/cursor_renderer.rs | 6 +++--- src/window.rs | 11 ++++++----- 11 files changed, 60 insertions(+), 63 deletions(-) diff --git a/src/bridge/handler.rs b/src/bridge/handler.rs index c28fc86..a80a5f1 100644 --- a/src/bridge/handler.rs +++ b/src/bridge/handler.rs @@ -2,12 +2,11 @@ use rmpv::Value; use nvim_rs::{Neovim, Handler, compat::tokio::Compat}; use async_trait::async_trait; use tokio::process::ChildStdin; -use tokio::sync::mpsc::{unbounded_channel, UnboundedSender}; use log::trace; use crate::error_handling::ResultPanicExplanation; use crate::editor::EDITOR; -use super::events::{RedrawEvent, parse_neovim_event}; +use super::events::parse_neovim_event; #[derive(Clone)] pub struct NeovimHandler(); diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index eb7a2f7..5c7800e 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -102,24 +102,20 @@ async fn start_process(mut receiver: UnboundedReceiver) { let nvim = Arc::new(nvim); tokio::spawn(async move { info!("UiCommand processor started"); - loop { - if let Some(commands) = drain(&mut receiver).await { - let (resize_list, other_commands): (Vec, Vec) = commands - .into_iter() - .partition(|command| command.is_resize()); - - for command in resize_list - .into_iter().last().into_iter() - .chain(other_commands.into_iter()) { - - let nvim = nvim.clone(); - tokio::spawn(async move { - trace!("Executing UiCommand: {:?}", &command); - command.execute(&nvim).await; - }); - } - } else { - break; + while let Some(commands) = drain(&mut receiver).await { + let (resize_list, other_commands): (Vec, Vec) = commands + .into_iter() + .partition(|command| command.is_resize()); + + for command in resize_list + .into_iter().last().into_iter() + .chain(other_commands.into_iter()) { + + let nvim = nvim.clone(); + tokio::spawn(async move { + trace!("Executing UiCommand: {:?}", &command); + command.execute(&nvim).await; + }); } } }); diff --git a/src/editor/cursor.rs b/src/editor/cursor.rs index a602fc2..72f85f7 100644 --- a/src/editor/cursor.rs +++ b/src/editor/cursor.rs @@ -63,7 +63,7 @@ impl Cursor { pub fn foreground(&self, default_colors: &Colors) -> Color4f { if let Some(style) = &self.style { - style.colors.foreground.clone().unwrap_or(default_colors.background.clone().unwrap()) + style.colors.foreground.clone().unwrap_or_else(||default_colors.background.clone().unwrap()) } else { default_colors.background.clone().unwrap() } @@ -71,7 +71,7 @@ impl Cursor { pub fn background(&self, default_colors: &Colors) -> Color4f { if let Some(style) = &self.style { - style.colors.background.clone().unwrap_or(default_colors.foreground.clone().unwrap()) + style.colors.background.clone().unwrap_or_else(||default_colors.foreground.clone().unwrap()) } else { default_colors.foreground.clone().unwrap() } @@ -86,13 +86,13 @@ impl Cursor { if let Some(style_id) = style_id { self.style = styles .get(style_id) - .map(|style_reference| style_reference.clone()); + .cloned(); } - self.cell_percentage = cell_percentage.clone(); - self.blinkwait = blinkwait.clone(); - self.blinkon = blinkon.clone(); - self.blinkoff = blinkoff.clone(); + self.cell_percentage = *cell_percentage; + self.blinkwait = *blinkwait; + self.blinkon = *blinkon; + self.blinkoff = *blinkoff; } } } diff --git a/src/editor/grid.rs b/src/editor/grid.rs index 22649a6..c235da3 100644 --- a/src/editor/grid.rs +++ b/src/editor/grid.rs @@ -54,11 +54,11 @@ impl CharacterGrid { } } - pub fn get_cell<'a>(&'a self, x: u64, y: u64) -> Option<&'a GridCell> { + pub fn get_cell(&self, x: u64, y: u64) -> Option<&GridCell> { self.cell_index(x,y).map(|idx| &self.characters[idx]) } - pub fn get_cell_mut<'a>(&'a mut self, x: u64, y: u64) -> Option<&'a mut GridCell> { + pub fn get_cell_mut(&mut self, x: u64, y: u64) -> Option<&mut GridCell> { self.cell_index(x,y).map(move |idx| &mut self.characters[idx]) } @@ -81,7 +81,7 @@ impl CharacterGrid { self.dirty.resize_with((self.width * self.height) as usize, || value); } - pub fn rows<'a>(&'a self) -> impl Iterator { + pub fn rows(&self) -> impl Iterator { (0..self.height) .map(move |row| { &self.characters[(row * self.width) as usize..((row + 1) * self.width) as usize] diff --git a/src/editor/mod.rs b/src/editor/mod.rs index ba05108..0a22b0b 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -154,7 +154,7 @@ impl Editor { return true; } } - return false; + false }).collect::>(); self.grid.set_dirty_all(false); @@ -167,7 +167,7 @@ impl Editor { fn draw_grid_line_cell(&mut self, row_index: u64, column_pos: &mut u64, cell: GridLineCell) { let style = match cell.highlight_id { Some(0) => None, - Some(style_id) => self.defined_styles.get(&style_id).map(|style| style.clone()), + Some(style_id) => self.defined_styles.get(&style_id).cloned(), None => self.previous_style.clone() }; @@ -182,7 +182,7 @@ impl Editor { } self.grid.set_dirty_cell(*column_pos, row_index); - *column_pos = *column_pos + 1; + *column_pos += 1; } else { for (i, character) in text.graphemes(true).enumerate() { if let Some(cell) = self.grid.get_cell_mut(i as u64 + *column_pos, row_index) { @@ -190,7 +190,7 @@ impl Editor { self.grid.set_dirty_cell(*column_pos, row_index); } } - *column_pos = *column_pos + text.graphemes(true).count() as u64; + *column_pos += text.graphemes(true).count() as u64; } self.previous_style = style; } @@ -244,10 +244,10 @@ impl Editor { trace!("Option set {:?}", &gui_option); match gui_option { GuiOption::GuiFont(font_description) => { - let parts: Vec<&str> = font_description.split(":").collect(); + let parts: Vec<&str> = font_description.split(':').collect(); self.font_name = Some(parts[0].to_string()); for part in parts.iter().skip(1) { - if part.starts_with("h") && part.len() > 1 { + if part.starts_with('h') && part.len() > 1 { self.font_size = part[1..].parse::().ok(); } } diff --git a/src/editor/style.rs b/src/editor/style.rs index 7854137..f060e98 100644 --- a/src/editor/style.rs +++ b/src/editor/style.rs @@ -29,21 +29,21 @@ pub struct Style { impl Style { pub fn foreground(&self, default_colors: &Colors) -> Color4f { if self.reverse { - self.colors.background.clone().unwrap_or(default_colors.background.clone().unwrap()) + self.colors.background.clone().unwrap_or_else(||default_colors.background.clone().unwrap()) } else { - self.colors.foreground.clone().unwrap_or(default_colors.foreground.clone().unwrap()) + self.colors.foreground.clone().unwrap_or_else(||default_colors.foreground.clone().unwrap()) } } pub fn background(&self, default_colors: &Colors) -> Color4f { if self.reverse { - self.colors.foreground.clone().unwrap_or(default_colors.foreground.clone().unwrap()) + self.colors.foreground.clone().unwrap_or_else(||default_colors.foreground.clone().unwrap()) } else { - self.colors.background.clone().unwrap_or(default_colors.background.clone().unwrap()) + self.colors.background.clone().unwrap_or_else(||default_colors.background.clone().unwrap()) } } pub fn special(&self, default_colors: &Colors) -> Color4f { - self.colors.special.clone().unwrap_or(default_colors.special.clone().unwrap()) + self.colors.special.clone().unwrap_or_else(||default_colors.special.clone().unwrap()) } } diff --git a/src/main.rs b/src/main.rs index 07f58cb..13a9528 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,19 +24,20 @@ use settings::SETTINGS; pub const INITIAL_DIMENSIONS: (u64, u64) = (100, 50); fn main() { - SETTINGS.neovim_arguments.store(Some(std::env::args().filter_map(|arg| { + SETTINGS.neovim_arguments.store(Some(std::env::args().filter(|arg| { if arg == "--log" { Logger::with_str("neovide") .log_to_file() .rotate(Criterion::Size(10_000_000), Naming::Timestamps, Cleanup::KeepLogFiles(1)) .start() .expect("Could not start logger"); - return None; + false } else if arg == "--noIdle" { SETTINGS.no_idle.store(true, Ordering::Relaxed); - return None; + false + } else { + true } - return Some(arg.into()); }).collect::>())); initialize(&BRIDGE); diff --git a/src/redraw_scheduler.rs b/src/redraw_scheduler.rs index b4c6519..70d1d0c 100644 --- a/src/redraw_scheduler.rs +++ b/src/redraw_scheduler.rs @@ -27,7 +27,7 @@ impl RedrawScheduler { pub fn schedule(&self, new_scheduled: Instant) { trace!("Redraw scheduled for {:?}", new_scheduled); let mut scheduled_frame = self.scheduled_frame.lock().unwrap(); - if let Some(previous_scheduled) = scheduled_frame.clone() { + if let Some(previous_scheduled) = *scheduled_frame { if new_scheduled < previous_scheduled { *scheduled_frame = Some(new_scheduled); } @@ -48,7 +48,7 @@ impl RedrawScheduler { true } else { let mut next_scheduled_frame = self.scheduled_frame.lock().unwrap(); - if let Some(scheduled_frame) = next_scheduled_frame.clone() { + if let Some(scheduled_frame) = *next_scheduled_frame { if scheduled_frame < Instant::now() { *next_scheduled_frame = None; true diff --git a/src/renderer/caching_shaper.rs b/src/renderer/caching_shaper.rs index 5710212..a8c25a7 100644 --- a/src/renderer/caching_shaper.rs +++ b/src/renderer/caching_shaper.rs @@ -7,14 +7,14 @@ use skribo::{LayoutSession, FontRef as SkriboFont, FontFamily, FontCollection, T use log::trace; -const STANDARD_CHARACTER_STRING: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; +const STANDARD_CHARACTER_STRING: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; -const MONOSPACE_FONT: &'static str = "Fira Code Regular Nerd Font Complete.otf"; -const MONOSPACE_BOLD_FONT: &'static str = "Fira Code Bold Nerd Font Complete.otf"; -const SYMBOL_FONT: &'static str = "DejaVuSansMono.ttf"; -const EMOJI_FONT: &'static str = "NotoColorEmoji.ttf"; -const WIDE_FONT: &'static str = "NotoSansMonoCJKjp-Regular.otf"; -const WIDE_BOLD_FONT: &'static str = "NotoSansMonoCJKjp-Bold.otf"; +const MONOSPACE_FONT: &str = "Fira Code Regular Nerd Font Complete.otf"; +const MONOSPACE_BOLD_FONT: &str = "Fira Code Bold Nerd Font Complete.otf"; +const SYMBOL_FONT: &str = "DejaVuSansMono.ttf"; +const EMOJI_FONT: &str = "NotoColorEmoji.ttf"; +const WIDE_FONT: &str = "NotoSansMonoCJKjp-Regular.otf"; +const WIDE_BOLD_FONT: &str = "NotoSansMonoCJKjp-Bold.otf"; #[cfg(target_os = "windows")] const SYSTEM_EMOJI_FONT: &str = "Segoe UI Emoji"; @@ -235,7 +235,7 @@ impl CachingShaper { .and_modify(|e| *e += 1) .or_insert(1); } - let (font_width, _) = amounts.into_iter().max_by_key(|(_, count)| count.clone()).unwrap(); + let (font_width, _) = amounts.into_iter().max_by_key(|(_, count)| *count).unwrap(); let font_width = font_width.parse::().unwrap(); (font_width, font_height) diff --git a/src/renderer/cursor_renderer.rs b/src/renderer/cursor_renderer.rs index da8a4c4..3505bef 100644 --- a/src/renderer/cursor_renderer.rs +++ b/src/renderer/cursor_renderer.rs @@ -55,7 +55,7 @@ impl BlinkStatus { BlinkState::Waiting => new_cursor.blinkwait, BlinkState::Off => new_cursor.blinkoff, BlinkState::On => new_cursor.blinkon - }.filter(|millis| millis > &0).map(|millis| Duration::from_millis(millis)); + }.filter(|millis| *millis > 0).map(Duration::from_millis); if delay.map(|delay| self.last_transition + delay < Instant::now()).unwrap_or(false) { self.state = match self.state { @@ -183,7 +183,7 @@ impl CursorRenderer { let (_, grid_y) = cursor.position; let (_, previous_y) = self.previous_position; if grid_y == editor.grid.height - 1 && previous_y != grid_y { - self.command_line_delay = self.command_line_delay + 1; + self.command_line_delay += 1; if self.command_line_delay < COMMAND_LINE_DELAY_FRAMES { self.previous_position } else { @@ -252,7 +252,7 @@ impl CursorRenderer { canvas.save(); canvas.clip_path(&path, None, Some(false)); - let blobs = &shaper.shape_cached(&character.to_string(), false, false); + let blobs = &shaper.shape_cached(&character, false, false); for blob in blobs.iter() { canvas.draw_text_blob(&blob, destination, &paint); } diff --git a/src/window.rs b/src/window.rs index 27dcdf6..a858f19 100644 --- a/src/window.rs +++ b/src/window.rs @@ -114,9 +114,10 @@ pub fn ui_loop() { } next_char_modifiers = input.modifiers; - construct_keybinding_string(input) - .map(UiCommand::Keyboard) - .map(|keybinding_string| BRIDGE.queue_command(keybinding_string)); + if let Some(keybinding_string) = construct_keybinding_string(input) + .map(UiCommand::Keyboard) { + BRIDGE.queue_command(keybinding_string); + } }, Event::WindowEvent { @@ -214,11 +215,11 @@ pub fn ui_loop() { if REDRAW_SCHEDULER.should_draw() || SETTINGS.no_idle.load(Ordering::Relaxed) { debug!("Render Triggered"); - if let Err(_) = skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| { + if skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| { if renderer.draw(canvas, coordinate_system_helper) { handle_new_grid_size(window.inner_size().to_logical(window.scale_factor()), &renderer) } - }) { + }).is_err() { error!("Render failed. Closing"); *control_flow = ControlFlow::Exit; return;