chore: fix clippy warnings

pull/9/head
wongjiahau 2 years ago
parent 36769cb3f6
commit b5d92aca45

@ -1385,8 +1385,7 @@ impl Component for EditorView {
if let Some(position) = config.explorer.is_embed() { if let Some(position) = config.explorer.is_embed() {
let area = if use_bufferline { let area = if use_bufferline {
area.clip_top(1) area.clip_top(1)
} } else {
else {
area area
}; };
explorer.content.render_embed(area, surface, cx, &position); explorer.content.render_embed(area, surface, cx, &position);
@ -1478,8 +1477,7 @@ impl Component for EditorView {
if let Some(position) = config.explorer.is_embed() { if let Some(position) = config.explorer.is_embed() {
let area = if use_bufferline { let area = if use_bufferline {
area.clip_top(1) area.clip_top(1)
} } else {
else {
area area
}; };
explore.content.render_embed(area, surface, cx, &position); explore.content.render_embed(area, surface, cx, &position);

@ -50,7 +50,7 @@ impl FileInfo {
fn get_text(&self) -> Cow<'static, str> { fn get_text(&self) -> Cow<'static, str> {
match self.file_type { match self.file_type {
FileType::Root => return format!("{}", self.path.display()).into(), FileType::Root => format!("{}", self.path.display()).into(),
FileType::File | FileType::Folder => self FileType::File | FileType::Folder => self
.path .path
.file_name() .file_name()
@ -107,14 +107,11 @@ impl TreeViewItem for FileInfo {
} }
fn is_parent(&self) -> bool { fn is_parent(&self) -> bool {
match self.file_type { matches!(self.file_type, FileType::Folder | FileType::Root)
FileType::Folder | FileType::Root => true,
_ => false,
}
} }
} }
fn dir_entry_to_file_info(entry: DirEntry, path: &PathBuf) -> Option<FileInfo> { fn dir_entry_to_file_info(entry: DirEntry, path: &Path) -> Option<FileInfo> {
entry.metadata().ok().map(|meta| { entry.metadata().ok().map(|meta| {
let file_type = match meta.is_dir() { let file_type = match meta.is_dir() {
true => FileType::Folder, true => FileType::Folder,
@ -196,7 +193,7 @@ impl Explorer {
} }
fn new_tree_view(root: PathBuf) -> Result<TreeView<FileInfo>> { fn new_tree_view(root: PathBuf) -> Result<TreeView<FileInfo>> {
let root = FileInfo::root(root.clone()); let root = FileInfo::root(root);
let children = root.get_children()?; let children = root.get_children()?;
Ok(TreeView::build_tree(root, children).with_enter_fn(Self::toggle_current)) Ok(TreeView::build_tree(root, children).with_enter_fn(Self::toggle_current))
} }
@ -368,7 +365,7 @@ impl Explorer {
self.prompt = Some(( self.prompt = Some((
PromptAction::RenameFile, PromptAction::RenameFile,
Prompt::new( Prompt::new(
format!(" Rename to ").into(), " Rename to ".into(),
None, None,
ui::completers::none, ui::completers::none,
|_, _, _| {}, |_, _, _| {},
@ -689,7 +686,7 @@ impl Explorer {
} }
fn change_root_parent_folder(&mut self) -> Result<()> { fn change_root_parent_folder(&mut self) -> Result<()> {
if let Some(parent) = self.state.current_root.parent().clone() { if let Some(parent) = self.state.current_root.parent() {
let path = parent.to_path_buf(); let path = parent.to_path_buf();
self.change_root(path) self.change_root(path)
} else { } else {
@ -725,7 +722,7 @@ impl Explorer {
} }
std::fs::rename(&item.path, &path)?; std::fs::rename(&item.path, &path)?;
self.tree.refresh()?; self.tree.refresh()?;
self.reveal_file(path.into()) self.reveal_file(path)
} }
fn remove_folder(&mut self) -> Result<()> { fn remove_folder(&mut self) -> Result<()> {
@ -752,7 +749,7 @@ fn close_documents(current_item_path: PathBuf, cx: &mut Context) -> Result<()> {
.map(|p| p.starts_with(&current_item_path)) .map(|p| p.starts_with(&current_item_path))
.unwrap_or(false) .unwrap_or(false)
{ {
Some(id.clone()) Some(*id)
} else { } else {
None None
} }
@ -855,8 +852,7 @@ fn get_preview(p: impl AsRef<Path>, max_line: usize) -> Result<Vec<String>> {
.filter_map(|entry| { .filter_map(|entry| {
entry entry
.ok() .ok()
.map(|entry| dir_entry_to_file_info(entry, &p.to_path_buf())) .and_then(|entry| dir_entry_to_file_info(entry, p))
.flatten()
}) })
.take(max_line) .take(max_line)
.collect::<Vec<_>>(); .collect::<Vec<_>>();

@ -29,7 +29,7 @@ pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent}; pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner}; pub use spinner::{ProgressSpinners, Spinner};
pub use text::Text; pub use text::Text;
pub use tree::{TreeViewItem, TreeOp, TreeView}; pub use tree::{TreeOp, TreeView, TreeViewItem};
use helix_core::regex::Regex; use helix_core::regex::Regex;
use helix_core::regex::RegexBuilder; use helix_core::regex::RegexBuilder;

@ -123,7 +123,7 @@ impl<'a, T> DoubleEndedIterator for TreeIter<'a, T> {
impl<'a, T> ExactSizeIterator for TreeIter<'a, T> {} impl<'a, T> ExactSizeIterator for TreeIter<'a, T> {}
impl<T: TreeViewItem> Tree<T> { impl<T: TreeViewItem> Tree<T> {
fn open(&mut self, filter: &String) -> Result<()> { fn open(&mut self, filter: &str) -> Result<()> {
if self.item.is_parent() { if self.item.is_parent() {
self.children = self.get_filtered_children(filter)?; self.children = self.get_filtered_children(filter)?;
self.is_opened = true; self.is_opened = true;
@ -136,12 +136,12 @@ impl<T: TreeViewItem> Tree<T> {
self.children = vec![]; self.children = vec![];
} }
fn refresh(&mut self, filter: &String) -> Result<()> { fn refresh(&mut self, filter: &str) -> Result<()> {
if !self.is_opened { if !self.is_opened {
return Ok(()); return Ok(());
} }
let latest_children = self.get_filtered_children(filter)?; let latest_children = self.get_filtered_children(filter)?;
let filtered = std::mem::replace(&mut self.children, vec![]) let filtered = std::mem::take(&mut self.children)
.into_iter() .into_iter()
// Remove children that does not exists in latest_children // Remove children that does not exists in latest_children
.filter(|tree| { .filter(|tree| {
@ -174,7 +174,7 @@ impl<T: TreeViewItem> Tree<T> {
Ok(()) Ok(())
} }
fn get_filtered_children(&self, filter: &String) -> Result<Vec<Tree<T>>> { fn get_filtered_children(&self, filter: &str) -> Result<Vec<Tree<T>>> {
Ok(vec_to_tree( Ok(vec_to_tree(
self.item self.item
.get_children()? .get_children()?
@ -242,7 +242,7 @@ impl<T> Tree<T> {
&self.item &self.item
} }
fn get<'a>(&'a self, index: usize) -> Option<&'a Tree<T>> { fn get(&self, index: usize) -> Option<&Tree<T>> {
if self.index == index { if self.index == index {
Some(self) Some(self)
} else { } else {
@ -261,7 +261,7 @@ impl<T> Tree<T> {
} }
fn len(&self) -> usize { fn len(&self) -> usize {
(1 as usize).saturating_add(self.children.iter().map(|elem| elem.len()).sum()) (1_usize).saturating_add(self.children.iter().map(|elem| elem.len()).sum())
} }
fn regenerate_index(&mut self) { fn regenerate_index(&mut self) {
@ -373,7 +373,7 @@ impl<T: TreeViewItem> TreeView<T> {
/// ///
/// vec!["helix-term", "src", "ui", "tree.rs"] /// vec!["helix-term", "src", "ui", "tree.rs"]
/// ///
pub fn reveal_item(&mut self, segments: Vec<String>, filter: &String) -> Result<()> { pub fn reveal_item(&mut self, segments: Vec<String>, filter: &str) -> Result<()> {
self.refresh_with_filter(filter)?; self.refresh_with_filter(filter)?;
// Expand the tree // Expand the tree
@ -447,7 +447,7 @@ impl<T: TreeViewItem> TreeView<T> {
Ok(()) Ok(())
} }
fn move_to_children(&mut self, filter: &String) -> Result<()> { fn move_to_children(&mut self, filter: &str) -> Result<()> {
let current = self.current_mut()?; let current = self.current_mut()?;
if current.is_opened { if current.is_opened {
self.set_selected(self.selected + 1); self.set_selected(self.selected + 1);
@ -466,7 +466,7 @@ impl<T: TreeViewItem> TreeView<T> {
self.refresh_with_filter(&self.filter.clone()) self.refresh_with_filter(&self.filter.clone())
} }
fn refresh_with_filter(&mut self, filter: &String) -> Result<()> { fn refresh_with_filter(&mut self, filter: &str) -> Result<()> {
self.tree.refresh(filter)?; self.tree.refresh(filter)?;
self.set_selected(self.selected); self.set_selected(self.selected);
Ok(()) Ok(())
@ -526,7 +526,7 @@ impl<T: TreeViewItem> TreeView<T> {
cx: &mut Context, cx: &mut Context,
params: &mut T::Params, params: &mut T::Params,
selected_index: usize, selected_index: usize,
filter: &String, filter: &str,
) -> Result<()> { ) -> Result<()> {
let selected_item = self.get_mut(selected_index)?; let selected_item = self.get_mut(selected_index)?;
if selected_item.is_opened { if selected_item.is_opened {
@ -561,7 +561,7 @@ impl<T: TreeViewItem> TreeView<T> {
} }
fn saved_view(&self) -> SavedView { fn saved_view(&self) -> SavedView {
self.saved_view.clone().unwrap_or_else(|| SavedView { self.saved_view.clone().unwrap_or(SavedView {
selected: self.selected, selected: self.selected,
}) })
} }
@ -776,7 +776,7 @@ fn render_tree<T: TreeViewItem>(
} }
impl<T: TreeViewItem + Clone> TreeView<T> { impl<T: TreeViewItem + Clone> TreeView<T> {
pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context, filter: &String) { pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context, filter: &str) {
let style = cx.editor.theme.get(&self.tree_symbol_style); let style = cx.editor.theme.get(&self.tree_symbol_style);
let filter_prompt_area = area.with_height(1); let filter_prompt_area = area.with_height(1);
@ -847,7 +847,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
} }
#[cfg(test)] #[cfg(test)]
pub fn render_to_string(&mut self, area: Rect, filter: &String) -> String { pub fn render_to_string(&mut self, area: Rect, filter: &str) -> String {
let lines = self.render_lines(area, filter); let lines = self.render_lines(area, filter);
lines lines
.into_iter() .into_iter()
@ -865,7 +865,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
.join("\n") .join("\n")
} }
fn render_lines(&mut self, area: Rect, filter: &String) -> Vec<RenderedLine> { fn render_lines(&mut self, area: Rect, filter: &str) -> Vec<RenderedLine> {
if let Some(pre_render) = self.pre_render.take() { if let Some(pre_render) = self.pre_render.take() {
pre_render(self, area); pre_render(self, area);
} }
@ -995,7 +995,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
event: &Event, event: &Event,
cx: &mut Context, cx: &mut Context,
params: &mut T::Params, params: &mut T::Params,
filter: &String, filter: &str,
) -> EventResult { ) -> EventResult {
let key_event = match event { let key_event = match event {
Event::Key(event) => event, Event::Key(event) => event,
@ -1085,7 +1085,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
} }
key!(Esc) | ctrl!('c') => { key!(Esc) | ctrl!('c') => {
self.filter.clear(); self.filter.clear();
self.refresh_with_filter(&"".to_string())?; self.refresh_with_filter("")?;
} }
_ => { _ => {
if let EventResult::Consumed(_) = if let EventResult::Consumed(_) =

@ -241,10 +241,7 @@ impl ExplorerConfig {
} }
pub fn is_overlay(&self) -> bool { pub fn is_overlay(&self) -> bool {
match self.position { matches!(self.position, ExplorerPosition::Overlay)
ExplorerPosition::Overlay => true,
_ => false,
}
} }
} }
@ -257,7 +254,7 @@ impl Default for ExplorerConfig {
} }
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct Config { pub struct Config {
/// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5. /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.

Loading…
Cancel
Save