Merge pull request #111 from jonvaldes/fix-clippy-issues

Fix a bunch of small issues reported by clippy
macos-click-through
Keith Simmons 5 years ago committed by GitHub
commit 260291e8b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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();

@ -102,24 +102,20 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
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<UiCommand>, Vec<UiCommand>) = 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<UiCommand>, Vec<UiCommand>) = 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;
});
}
}
});

@ -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;
}
}
}

@ -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<Item=&'a[GridCell]> {
pub fn rows(&self) -> impl Iterator<Item=&[GridCell]> {
(0..self.height)
.map(move |row| {
&self.characters[(row * self.width) as usize..((row + 1) * self.width) as usize]

@ -154,7 +154,7 @@ impl Editor {
return true;
}
}
return false;
false
}).collect::<Vec<DrawCommand>>();
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::<f32>().ok();
}
}

@ -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())
}
}

@ -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::<Vec<String>>()));
initialize(&BRIDGE);

@ -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

@ -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::<f32>().unwrap();
(font_width, font_height)

@ -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);
}

@ -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;

Loading…
Cancel
Save