One big cleanup pass of clippy lints

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
ForLoveOfCats 2022-08-10 17:39:24 -04:00 committed by K Simmons
parent e7540d2833
commit 8ba2f77148
138 changed files with 1328 additions and 1366 deletions

View file

@ -190,7 +190,7 @@ impl RelativeHighlightedRange {
let end_x =
origin.x() + self.range.end as f32 * layout.size.cell_width + layout.size.cell_width;
return HighlightedRangeLine { start_x, end_x };
HighlightedRangeLine { start_x, end_x }
}
}
@ -273,7 +273,7 @@ impl TerminalEl {
cur_rect = cur_rect.take().map(|rect| rect.extend());
} else {
cur_alac_color = Some(bg);
if let Some(_) = cur_rect {
if cur_rect.is_some() {
rects.push(cur_rect.take().unwrap());
}
cur_rect = Some(LayoutRect::new(
@ -402,7 +402,7 @@ impl TerminalEl {
RunStyle {
color: fg,
font_id: font_id,
font_id,
underline,
}
}
@ -416,9 +416,9 @@ impl TerminalEl {
display_offset: usize,
cx: &mut PaintContext,
) {
let mouse_down_connection = self.terminal.clone();
let click_connection = self.terminal.clone();
let drag_connection = self.terminal.clone();
let mouse_down_connection = self.terminal;
let click_connection = self.terminal;
let drag_connection = self.terminal;
cx.scene.push_mouse_region(
MouseRegion::new(view_id, None, visible_bounds)
.on_down(
@ -500,7 +500,7 @@ impl TerminalEl {
.terminal_overrides
.font_family
.as_ref()
.or_else(|| settings.terminal_defaults.font_family.as_ref())
.or(settings.terminal_defaults.font_family.as_ref())
.and_then(|family_name| font_cache.load_family(&[family_name]).log_err())
.unwrap_or(settings.buffer_font_family);
@ -581,7 +581,7 @@ impl Element for TerminalEl {
//Setup layout information
let terminal_theme = settings.theme.terminal.clone(); //TODO: Try to minimize this clone.
let text_style = TerminalEl::make_text_style(font_cache, &settings);
let text_style = TerminalEl::make_text_style(font_cache, settings);
let selection_color = settings.theme.editor.selection.selection;
let dimensions = {
let line_height = font_cache.line_height(text_style.font_size);
@ -590,9 +590,9 @@ impl Element for TerminalEl {
};
let background_color = if self.modal {
terminal_theme.colors.modal_background.clone()
terminal_theme.colors.modal_background
} else {
terminal_theme.colors.background.clone()
terminal_theme.colors.background
};
let (cells, selection, cursor, display_offset, cursor_text) = self
@ -614,17 +614,17 @@ impl Element for TerminalEl {
// && !ic.flags.contains(Flags::INVERSE))
// })
.map(|ic| IndexedCell {
point: ic.point.clone(),
point: ic.point,
cell: ic.cell.clone(),
}),
);
(
cells,
content.selection.clone(),
content.cursor.clone(),
content.display_offset.clone(),
cursor_text.clone(),
content.selection,
content.cursor,
content.display_offset,
cursor_text,
)
})
});
@ -666,7 +666,7 @@ impl Element for TerminalEl {
dimensions.line_height,
terminal_theme.colors.cursor,
CursorShape::Block,
Some(cursor_text.clone()),
Some(cursor_text),
)
},
)
@ -721,7 +721,7 @@ impl Element for TerminalEl {
});
for rect in &layout.rects {
rect.paint(origin, &layout, cx)
rect.paint(origin, layout, cx)
}
});
@ -786,11 +786,11 @@ impl Element for TerminalEl {
let vertical_scroll =
(delta.y() / layout.size.line_height) * ALACRITTY_SCROLL_MULTIPLIER;
self.terminal.upgrade(cx.app).map(|terminal| {
if let Some(terminal) = self.terminal.upgrade(cx.app) {
terminal.update(cx.app, |term, _| {
term.scroll(Scroll::Delta(vertical_scroll.round() as i32))
});
});
}
cx.notify();
})

View file

@ -82,7 +82,7 @@ impl ConnectedView {
has_new_content: true,
has_bell: false,
modal,
context_menu: cx.add_view(|cx| ContextMenu::new(cx)),
context_menu: cx.add_view(ContextMenu::new),
}
}
@ -127,9 +127,9 @@ impl ConnectedView {
///Attempt to paste the clipboard into the terminal
fn paste(&mut self, _: &Paste, cx: &mut ViewContext<Self>) {
cx.read_from_clipboard().map(|item| {
if let Some(item) = cx.read_from_clipboard() {
self.terminal.read(cx).paste(item.text());
});
}
}
///Synthesize the keyboard event corresponding to 'up'

View file

@ -110,7 +110,7 @@ pub fn get_color_at_index(index: &usize, colors: &TerminalColors) -> Color {
///
///This function does the reverse, calculating the r, g, and b components from a given index.
fn rgb_for_index(i: &u8) -> (u8, u8, u8) {
debug_assert!(i >= &16 && i <= &231);
debug_assert!((&16..=&231).contains(&i));
let i = i - 16;
let r = (i - (i % 36)) / 36;
let g = ((i % 36) - (i % 6)) / 6;

View file

@ -48,7 +48,7 @@ pub fn might_convert(keystroke: &Keystroke) -> bool {
}
pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode) -> Option<String> {
let modifiers = Modifiers::new(&keystroke);
let modifiers = Modifiers::new(keystroke);
// Manual Bindings including modifiers
let manual_esc_str = match (keystroke.key.as_ref(), &modifiers) {
@ -204,7 +204,7 @@ pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode) -> Option<String> {
// Automated bindings applying modifiers
if modifiers.any() {
let modifier_code = modifier_code(&keystroke);
let modifier_code = modifier_code(keystroke);
let modified_esc_str = match keystroke.key.as_ref() {
"up" => Some(format!("\x1b[1;{}A", modifier_code)),
"down" => Some(format!("\x1b[1;{}B", modifier_code)),

View file

@ -58,9 +58,7 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
let terminal_handle = connected.read(cx).handle();
// Set the global immediately if terminal construction was successful,
// in case the user opens the command palette
cx.set_global::<Option<StoredTerminal>>(Some(StoredTerminal(
terminal_handle.clone(),
)));
cx.set_global::<Option<StoredTerminal>>(Some(StoredTerminal(terminal_handle)));
}
}
}

View file

@ -137,13 +137,13 @@ impl Default for TerminalSize {
}
}
impl Into<WindowSize> for TerminalSize {
fn into(self) -> WindowSize {
impl From<TerminalSize> for WindowSize {
fn from(val: TerminalSize) -> Self {
WindowSize {
num_lines: self.num_lines() as u16,
num_cols: self.num_columns() as u16,
cell_width: self.cell_width() as u16,
cell_height: self.line_height() as u16,
num_lines: val.num_lines() as u16,
num_cols: val.num_columns() as u16,
cell_width: val.cell_width() as u16,
cell_height: val.line_height() as u16,
}
}
}
@ -269,7 +269,7 @@ impl TerminalBuilder {
}
};
let mut env = env.unwrap_or_else(|| HashMap::new());
let mut env = env.unwrap_or_default();
//TODO: Properly set the current locale,
env.insert("LC_ALL".to_string(), "en_US.UTF-8".to_string());
@ -293,7 +293,7 @@ impl TerminalBuilder {
let term = Arc::new(FairMutex::new(term));
//Setup the pty...
let pty = match tty::new(&pty_config, initial_size.clone().into(), None) {
let pty = match tty::new(&pty_config, initial_size.into(), None) {
Ok(pty) => pty,
Err(error) => {
bail!(TerminalError {
@ -321,7 +321,7 @@ impl TerminalBuilder {
//And connect them together
let event_loop = EventLoop::new(
term.clone(),
ZedListener(events_tx.clone()),
ZedListener(events_tx),
pty,
pty_config.hold,
false,
@ -379,7 +379,7 @@ impl TerminalBuilder {
}
}
if events.len() == 0 {
if events.is_empty() {
smol::future::yield_now().await;
break 'outer;
} else {
@ -459,11 +459,11 @@ impl Terminal {
AlacTermEvent::ClipboardLoad(_, format) => self.notify_pty(format(
&cx.read_from_clipboard()
.map(|ci| ci.text().to_string())
.unwrap_or("".to_string()),
.unwrap_or_else(|| "".to_string()),
)),
AlacTermEvent::PtyWrite(out) => self.notify_pty(out.clone()),
AlacTermEvent::TextAreaSizeRequest(format) => {
self.notify_pty(format(self.cur_size.clone().into()))
self.notify_pty(format(self.cur_size.into()))
}
AlacTermEvent::CursorBlinkingChange => {
//TODO whatever state we need to set to get the cursor blinking
@ -500,24 +500,19 @@ impl Terminal {
) {
// TODO: Handle is_self_focused in subscription on terminal view
match event {
InternalEvent::TermEvent(term_event) => match term_event {
//Needs to lock
AlacTermEvent::ColorRequest(index, format) => {
InternalEvent::TermEvent(term_event) => {
if let AlacTermEvent::ColorRequest(index, format) = term_event {
let color = term.colors()[*index].unwrap_or_else(|| {
let term_style = &cx.global::<Settings>().theme.terminal;
to_alac_rgb(get_color_at_index(index, &term_style.colors))
});
self.notify_pty(format(color))
}
_ => {} //Other events are handled in the event loop
},
}
InternalEvent::Resize(new_size) => {
self.cur_size = new_size.clone();
self.cur_size = *new_size;
self.pty_tx
.0
.send(Msg::Resize(new_size.clone().into()))
.ok();
self.pty_tx.0.send(Msg::Resize((*new_size).into())).ok();
term.resize(*new_size);
}
@ -553,7 +548,7 @@ impl Terminal {
///Resize the terminal and the PTY.
pub fn set_size(&mut self, new_size: TerminalSize) {
self.events.push(InternalEvent::Resize(new_size.into()))
self.events.push(InternalEvent::Resize(new_size))
}
pub fn clear(&mut self) {
@ -574,7 +569,7 @@ impl Terminal {
pub fn paste(&self, text: &str) {
if self.last_mode.contains(TermMode::BRACKETED_PASTE) {
self.notify_pty("\x1b[200~".to_string());
self.notify_pty(text.replace('\x1b', "").to_string());
self.notify_pty(text.replace('\x1b', ""));
self.notify_pty("\x1b[201~".to_string());
} else {
self.notify_pty(text.replace("\r\n", "\r").replace('\n', "\r"));
@ -597,7 +592,7 @@ impl Terminal {
}
// self.utilization = Self::estimate_utilization(term.take_last_processed_bytes());
self.last_mode = term.mode().clone();
self.last_mode = *term.mode();
let content = term.renderable_content();
@ -668,7 +663,7 @@ mod tests {
mod alacritty_unix {
use alacritty_terminal::config::Program;
use gpui::anyhow::{bail, Result};
use libc;
use std::ffi::CStr;
use std::mem::MaybeUninit;
use std::ptr;

View file

@ -99,7 +99,7 @@ impl TerminalView {
Ok(terminal) => {
let terminal = cx.add_model(|cx| terminal.subscribe(cx));
let view = cx.add_view(|cx| ConnectedView::from_terminal(terminal, modal, cx));
cx.subscribe(&view, |_this, _content, event, cx| cx.emit(event.clone()))
cx.subscribe(&view, |_this, _content, event, cx| cx.emit(*event))
.detach();
TerminalContent::Connected(view)
}
@ -206,7 +206,7 @@ impl View for ErrorView {
)
.with_child(Text::new(program_text, style.clone()).contained().boxed())
.with_child(Text::new(directory_text, style.clone()).contained().boxed())
.with_child(Text::new(error_text, style.clone()).contained().boxed())
.with_child(Text::new(error_text, style).contained().boxed())
.aligned()
.boxed()
}
@ -333,7 +333,7 @@ pub fn get_working_directory(
.filter(|dir| dir.is_dir())
}
};
res.or_else(|| home_dir())
res.or_else(home_dir)
}
///Get's the first project's home directory, or the home directory