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

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

@ -29,7 +29,7 @@ pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner};
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::RegexBuilder;

@ -123,7 +123,7 @@ impl<'a, T> DoubleEndedIterator for TreeIter<'a, T> {
impl<'a, T> ExactSizeIterator for TreeIter<'a, 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() {
self.children = self.get_filtered_children(filter)?;
self.is_opened = true;
@ -136,12 +136,12 @@ impl<T: TreeViewItem> Tree<T> {
self.children = vec![];
}
fn refresh(&mut self, filter: &String) -> Result<()> {
fn refresh(&mut self, filter: &str) -> Result<()> {
if !self.is_opened {
return Ok(());
}
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()
// Remove children that does not exists in latest_children
.filter(|tree| {
@ -174,7 +174,7 @@ impl<T: TreeViewItem> Tree<T> {
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(
self.item
.get_children()?
@ -242,7 +242,7 @@ impl<T> Tree<T> {
&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 {
Some(self)
} else {
@ -261,7 +261,7 @@ impl<T> Tree<T> {
}
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) {
@ -373,7 +373,7 @@ impl<T: TreeViewItem> TreeView<T> {
///
/// 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)?;
// Expand the tree
@ -447,7 +447,7 @@ impl<T: TreeViewItem> TreeView<T> {
Ok(())
}
fn move_to_children(&mut self, filter: &String) -> Result<()> {
fn move_to_children(&mut self, filter: &str) -> Result<()> {
let current = self.current_mut()?;
if current.is_opened {
self.set_selected(self.selected + 1);
@ -466,7 +466,7 @@ impl<T: TreeViewItem> TreeView<T> {
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.set_selected(self.selected);
Ok(())
@ -526,7 +526,7 @@ impl<T: TreeViewItem> TreeView<T> {
cx: &mut Context,
params: &mut T::Params,
selected_index: usize,
filter: &String,
filter: &str,
) -> Result<()> {
let selected_item = self.get_mut(selected_index)?;
if selected_item.is_opened {
@ -561,7 +561,7 @@ impl<T: TreeViewItem> TreeView<T> {
}
fn saved_view(&self) -> SavedView {
self.saved_view.clone().unwrap_or_else(|| SavedView {
self.saved_view.clone().unwrap_or(SavedView {
selected: self.selected,
})
}
@ -776,7 +776,7 @@ fn render_tree<T: TreeViewItem>(
}
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 filter_prompt_area = area.with_height(1);
@ -847,7 +847,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
}
#[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);
lines
.into_iter()
@ -865,7 +865,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
.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() {
pre_render(self, area);
}
@ -995,7 +995,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
event: &Event,
cx: &mut Context,
params: &mut T::Params,
filter: &String,
filter: &str,
) -> EventResult {
let key_event = match event {
Event::Key(event) => event,
@ -1085,7 +1085,7 @@ impl<T: TreeViewItem + Clone> TreeView<T> {
}
key!(Esc) | ctrl!('c') => {
self.filter.clear();
self.refresh_with_filter(&"".to_string())?;
self.refresh_with_filter("")?;
}
_ => {
if let EventResult::Consumed(_) =

@ -241,10 +241,7 @@ impl ExplorerConfig {
}
pub fn is_overlay(&self) -> bool {
match self.position {
ExplorerPosition::Overlay => true,
_ => false,
}
matches!(self.position, ExplorerPosition::Overlay)
}
}
@ -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)]
pub struct Config {
/// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.

Loading…
Cancel
Save