Auto-fix clippy::collapsible_if violations (#36428)

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-08-19 15:27:24 +02:00 committed by GitHub
parent 9e8ec72bd5
commit 8f567383e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
281 changed files with 6628 additions and 7089 deletions

View file

@ -652,8 +652,8 @@ impl ProjectPanel {
focus_opened_item,
allow_preview,
} => {
if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) {
if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx)
&& let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
let file_path = entry.path.clone();
let worktree_id = worktree.read(cx).id();
let entry_id = entry.id;
@ -703,11 +703,10 @@ impl ProjectPanel {
}
}
}
}
}
&Event::SplitEntry { entry_id } => {
if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) {
if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx)
&& let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
workspace
.split_path(
ProjectPath {
@ -718,7 +717,6 @@ impl ProjectPanel {
)
.detach_and_log_err(cx);
}
}
}
_ => {}
@ -1002,10 +1000,10 @@ impl ProjectPanel {
if let Some(parent_path) = entry.path.parent() {
let snapshot = worktree.snapshot();
let mut child_entries = snapshot.child_entries(parent_path);
if let Some(child) = child_entries.next() {
if child_entries.next().is_none() {
return child.kind.is_dir();
}
if let Some(child) = child_entries.next()
&& child_entries.next().is_none()
{
return child.kind.is_dir();
}
};
false
@ -1016,10 +1014,10 @@ impl ProjectPanel {
let snapshot = worktree.snapshot();
let mut child_entries = snapshot.child_entries(&entry.path);
if let Some(child) = child_entries.next() {
if child_entries.next().is_none() {
return child.kind.is_dir();
}
if let Some(child) = child_entries.next()
&& child_entries.next().is_none()
{
return child.kind.is_dir();
}
}
false
@ -1032,12 +1030,12 @@ impl ProjectPanel {
cx: &mut Context<Self>,
) {
if let Some((worktree, entry)) = self.selected_entry(cx) {
if let Some(folded_ancestors) = self.ancestors.get_mut(&entry.id) {
if folded_ancestors.current_ancestor_depth > 0 {
folded_ancestors.current_ancestor_depth -= 1;
cx.notify();
return;
}
if let Some(folded_ancestors) = self.ancestors.get_mut(&entry.id)
&& folded_ancestors.current_ancestor_depth > 0
{
folded_ancestors.current_ancestor_depth -= 1;
cx.notify();
return;
}
if entry.is_dir() {
let worktree_id = worktree.id();
@ -1079,12 +1077,12 @@ impl ProjectPanel {
fn collapse_entry(&mut self, entry: Entry, worktree: Entity<Worktree>, cx: &mut Context<Self>) {
let worktree = worktree.read(cx);
if let Some(folded_ancestors) = self.ancestors.get_mut(&entry.id) {
if folded_ancestors.current_ancestor_depth + 1 < folded_ancestors.max_ancestor_depth() {
folded_ancestors.current_ancestor_depth += 1;
cx.notify();
return;
}
if let Some(folded_ancestors) = self.ancestors.get_mut(&entry.id)
&& folded_ancestors.current_ancestor_depth + 1 < folded_ancestors.max_ancestor_depth()
{
folded_ancestors.current_ancestor_depth += 1;
cx.notify();
return;
}
let worktree_id = worktree.id();
let expanded_dir_ids =
@ -1137,23 +1135,23 @@ impl ProjectPanel {
window: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx) {
if let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree_id) {
self.project.update(cx, |project, cx| {
match expanded_dir_ids.binary_search(&entry_id) {
Ok(ix) => {
expanded_dir_ids.remove(ix);
}
Err(ix) => {
project.expand_entry(worktree_id, entry_id, cx);
expanded_dir_ids.insert(ix, entry_id);
}
if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx)
&& let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree_id)
{
self.project.update(cx, |project, cx| {
match expanded_dir_ids.binary_search(&entry_id) {
Ok(ix) => {
expanded_dir_ids.remove(ix);
}
});
self.update_visible_entries(Some((worktree_id, entry_id)), cx);
window.focus(&self.focus_handle);
cx.notify();
}
Err(ix) => {
project.expand_entry(worktree_id, entry_id, cx);
expanded_dir_ids.insert(ix, entry_id);
}
}
});
self.update_visible_entries(Some((worktree_id, entry_id)), cx);
window.focus(&self.focus_handle);
cx.notify();
}
}
@ -1163,20 +1161,20 @@ impl ProjectPanel {
window: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx) {
if let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree_id) {
match expanded_dir_ids.binary_search(&entry_id) {
Ok(_ix) => {
self.collapse_all_for_entry(worktree_id, entry_id, cx);
}
Err(_ix) => {
self.expand_all_for_entry(worktree_id, entry_id, cx);
}
if let Some(worktree_id) = self.project.read(cx).worktree_id_for_entry(entry_id, cx)
&& let Some(expanded_dir_ids) = self.expanded_dir_ids.get_mut(&worktree_id)
{
match expanded_dir_ids.binary_search(&entry_id) {
Ok(_ix) => {
self.collapse_all_for_entry(worktree_id, entry_id, cx);
}
Err(_ix) => {
self.expand_all_for_entry(worktree_id, entry_id, cx);
}
self.update_visible_entries(Some((worktree_id, entry_id)), cx);
window.focus(&self.focus_handle);
cx.notify();
}
self.update_visible_entries(Some((worktree_id, entry_id)), cx);
window.focus(&self.focus_handle);
cx.notify();
}
}
@ -1251,20 +1249,20 @@ impl ProjectPanel {
}
fn select_previous(&mut self, _: &SelectPrevious, window: &mut Window, cx: &mut Context<Self>) {
if let Some(edit_state) = &self.edit_state {
if edit_state.processing_filename.is_none() {
self.filename_editor.update(cx, |editor, cx| {
editor.move_to_beginning_of_line(
&editor::actions::MoveToBeginningOfLine {
stop_at_soft_wraps: false,
stop_at_indent: false,
},
window,
cx,
);
});
return;
}
if let Some(edit_state) = &self.edit_state
&& edit_state.processing_filename.is_none()
{
self.filename_editor.update(cx, |editor, cx| {
editor.move_to_beginning_of_line(
&editor::actions::MoveToBeginningOfLine {
stop_at_soft_wraps: false,
stop_at_indent: false,
},
window,
cx,
);
});
return;
}
if let Some(selection) = self.selection {
let (mut worktree_ix, mut entry_ix, _) =
@ -1341,39 +1339,37 @@ impl ProjectPanel {
.project
.read(cx)
.worktree_for_id(edit_state.worktree_id, cx)
&& let Some(entry) = worktree.read(cx).entry_for_id(edit_state.entry_id)
{
if let Some(entry) = worktree.read(cx).entry_for_id(edit_state.entry_id) {
let mut already_exists = false;
if edit_state.is_new_entry() {
let new_path = entry.path.join(filename.trim_start_matches('/'));
if worktree
.read(cx)
.entry_for_path(new_path.as_path())
.is_some()
{
already_exists = true;
}
} else {
let new_path = if let Some(parent) = entry.path.clone().parent() {
parent.join(&filename)
} else {
filename.clone().into()
};
if let Some(existing) = worktree.read(cx).entry_for_path(new_path.as_path())
{
if existing.id != entry.id {
already_exists = true;
}
}
};
if already_exists {
edit_state.validation_state = ValidationState::Error(format!(
"File or directory '{}' already exists at location. Please choose a different name.",
filename
));
cx.notify();
return;
let mut already_exists = false;
if edit_state.is_new_entry() {
let new_path = entry.path.join(filename.trim_start_matches('/'));
if worktree
.read(cx)
.entry_for_path(new_path.as_path())
.is_some()
{
already_exists = true;
}
} else {
let new_path = if let Some(parent) = entry.path.clone().parent() {
parent.join(&filename)
} else {
filename.clone().into()
};
if let Some(existing) = worktree.read(cx).entry_for_path(new_path.as_path())
&& existing.id != entry.id
{
already_exists = true;
}
};
if already_exists {
edit_state.validation_state = ValidationState::Error(format!(
"File or directory '{}' already exists at location. Please choose a different name.",
filename
));
cx.notify();
return;
}
}
let trimmed_filename = filename.trim();
@ -1477,14 +1473,13 @@ impl ProjectPanel {
}
Ok(CreatedEntry::Included(new_entry)) => {
project_panel.update( cx, |project_panel, cx| {
if let Some(selection) = &mut project_panel.selection {
if selection.entry_id == edited_entry_id {
if let Some(selection) = &mut project_panel.selection
&& selection.entry_id == edited_entry_id {
selection.worktree_id = worktree_id;
selection.entry_id = new_entry.id;
project_panel.marked_entries.clear();
project_panel.expand_to_selection(cx);
}
}
project_panel.update_visible_entries(None, cx);
if is_new_entry && !is_dir {
project_panel.open_entry(new_entry.id, true, false, cx);
@ -1617,11 +1612,11 @@ impl ProjectPanel {
directory_id = entry.id;
break;
} else {
if let Some(parent_path) = entry.path.parent() {
if let Some(parent_entry) = worktree.entry_for_path(parent_path) {
entry = parent_entry;
continue;
}
if let Some(parent_path) = entry.path.parent()
&& let Some(parent_entry) = worktree.entry_for_path(parent_path)
{
entry = parent_entry;
continue;
}
return;
}
@ -1675,57 +1670,56 @@ impl ProjectPanel {
worktree_id,
entry_id,
}) = self.selection
&& let Some(worktree) = self.project.read(cx).worktree_for_id(worktree_id, cx)
{
if let Some(worktree) = self.project.read(cx).worktree_for_id(worktree_id, cx) {
let sub_entry_id = self.unflatten_entry_id(entry_id);
if let Some(entry) = worktree.read(cx).entry_for_id(sub_entry_id) {
#[cfg(target_os = "windows")]
if Some(entry) == worktree.read(cx).root_entry() {
let sub_entry_id = self.unflatten_entry_id(entry_id);
if let Some(entry) = worktree.read(cx).entry_for_id(sub_entry_id) {
#[cfg(target_os = "windows")]
if Some(entry) == worktree.read(cx).root_entry() {
return;
}
if Some(entry) == worktree.read(cx).root_entry() {
let settings = ProjectPanelSettings::get_global(cx);
let visible_worktrees_count =
self.project.read(cx).visible_worktrees(cx).count();
if settings.hide_root && visible_worktrees_count == 1 {
return;
}
if Some(entry) == worktree.read(cx).root_entry() {
let settings = ProjectPanelSettings::get_global(cx);
let visible_worktrees_count =
self.project.read(cx).visible_worktrees(cx).count();
if settings.hide_root && visible_worktrees_count == 1 {
return;
}
}
self.edit_state = Some(EditState {
worktree_id,
entry_id: sub_entry_id,
leaf_entry_id: Some(entry_id),
is_dir: entry.is_dir(),
processing_filename: None,
previously_focused: None,
depth: 0,
validation_state: ValidationState::None,
});
let file_name = entry
.path
.file_name()
.map(|s| s.to_string_lossy())
.unwrap_or_default()
.to_string();
let selection = selection.unwrap_or_else(|| {
let file_stem = entry.path.file_stem().map(|s| s.to_string_lossy());
let selection_end =
file_stem.map_or(file_name.len(), |file_stem| file_stem.len());
0..selection_end
});
self.filename_editor.update(cx, |editor, cx| {
editor.set_text(file_name, window, cx);
editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([selection])
});
window.focus(&editor.focus_handle(cx));
});
self.update_visible_entries(None, cx);
self.autoscroll(cx);
cx.notify();
}
self.edit_state = Some(EditState {
worktree_id,
entry_id: sub_entry_id,
leaf_entry_id: Some(entry_id),
is_dir: entry.is_dir(),
processing_filename: None,
previously_focused: None,
depth: 0,
validation_state: ValidationState::None,
});
let file_name = entry
.path
.file_name()
.map(|s| s.to_string_lossy())
.unwrap_or_default()
.to_string();
let selection = selection.unwrap_or_else(|| {
let file_stem = entry.path.file_stem().map(|s| s.to_string_lossy());
let selection_end =
file_stem.map_or(file_name.len(), |file_stem| file_stem.len());
0..selection_end
});
self.filename_editor.update(cx, |editor, cx| {
editor.set_text(file_name, window, cx);
editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([selection])
});
window.focus(&editor.focus_handle(cx));
});
self.update_visible_entries(None, cx);
self.autoscroll(cx);
cx.notify();
}
}
}
@ -1831,10 +1825,10 @@ impl ProjectPanel {
};
let next_selection = self.find_next_selection_after_deletion(items_to_delete, cx);
cx.spawn_in(window, async move |panel, cx| {
if let Some(answer) = answer {
if answer.await != Ok(0) {
return anyhow::Ok(());
}
if let Some(answer) = answer
&& answer.await != Ok(0)
{
return anyhow::Ok(());
}
for (entry_id, _) in file_paths {
panel
@ -1999,19 +1993,19 @@ impl ProjectPanel {
}
fn select_next(&mut self, _: &SelectNext, window: &mut Window, cx: &mut Context<Self>) {
if let Some(edit_state) = &self.edit_state {
if edit_state.processing_filename.is_none() {
self.filename_editor.update(cx, |editor, cx| {
editor.move_to_end_of_line(
&editor::actions::MoveToEndOfLine {
stop_at_soft_wraps: false,
},
window,
cx,
);
});
return;
}
if let Some(edit_state) = &self.edit_state
&& edit_state.processing_filename.is_none()
{
self.filename_editor.update(cx, |editor, cx| {
editor.move_to_end_of_line(
&editor::actions::MoveToEndOfLine {
stop_at_soft_wraps: false,
},
window,
cx,
);
});
return;
}
if let Some(selection) = self.selection {
let (mut worktree_ix, mut entry_ix, _) =
@ -2032,20 +2026,19 @@ impl ProjectPanel {
entries,
..
}) = self.visible_entries.get(worktree_ix)
&& let Some(entry) = entries.get(entry_ix)
{
if let Some(entry) = entries.get(entry_ix) {
let selection = SelectedEntry {
worktree_id: *worktree_id,
entry_id: entry.id,
};
self.selection = Some(selection);
if window.modifiers().shift {
self.marked_entries.push(selection);
}
self.autoscroll(cx);
cx.notify();
let selection = SelectedEntry {
worktree_id: *worktree_id,
entry_id: entry.id,
};
self.selection = Some(selection);
if window.modifiers().shift {
self.marked_entries.push(selection);
}
self.autoscroll(cx);
cx.notify();
}
} else {
self.select_first(&SelectFirst {}, window, cx);
@ -2274,19 +2267,18 @@ impl ProjectPanel {
entries,
..
}) = self.visible_entries.first()
&& let Some(entry) = entries.first()
{
if let Some(entry) = entries.first() {
let selection = SelectedEntry {
worktree_id: *worktree_id,
entry_id: entry.id,
};
self.selection = Some(selection);
if window.modifiers().shift {
self.marked_entries.push(selection);
}
self.autoscroll(cx);
cx.notify();
let selection = SelectedEntry {
worktree_id: *worktree_id,
entry_id: entry.id,
};
self.selection = Some(selection);
if window.modifiers().shift {
self.marked_entries.push(selection);
}
self.autoscroll(cx);
cx.notify();
}
}
@ -2947,10 +2939,10 @@ impl ProjectPanel {
let Some(entry) = worktree.entry_for_path(path) else {
continue;
};
if entry.is_dir() {
if let Err(idx) = expanded_dir_ids.binary_search(&entry.id) {
expanded_dir_ids.insert(idx, entry.id);
}
if entry.is_dir()
&& let Err(idx) = expanded_dir_ids.binary_search(&entry.id)
{
expanded_dir_ids.insert(idx, entry.id);
}
}
@ -3024,15 +3016,16 @@ impl ProjectPanel {
let mut new_entry_parent_id = None;
let mut new_entry_kind = EntryKind::Dir;
if let Some(edit_state) = &self.edit_state {
if edit_state.worktree_id == worktree_id && edit_state.is_new_entry() {
new_entry_parent_id = Some(edit_state.entry_id);
new_entry_kind = if edit_state.is_dir {
EntryKind::Dir
} else {
EntryKind::File
};
}
if let Some(edit_state) = &self.edit_state
&& edit_state.worktree_id == worktree_id
&& edit_state.is_new_entry()
{
new_entry_parent_id = Some(edit_state.entry_id);
new_entry_kind = if edit_state.is_dir {
EntryKind::Dir
} else {
EntryKind::File
};
}
let mut visible_worktree_entries = Vec::new();
@ -3054,19 +3047,18 @@ impl ProjectPanel {
}
if auto_collapse_dirs && entry.kind.is_dir() {
auto_folded_ancestors.push(entry.id);
if !self.unfolded_dir_ids.contains(&entry.id) {
if let Some(root_path) = worktree_snapshot.root_entry() {
let mut child_entries = worktree_snapshot.child_entries(&entry.path);
if let Some(child) = child_entries.next() {
if entry.path != root_path.path
&& child_entries.next().is_none()
&& child.kind.is_dir()
{
entry_iter.advance();
if !self.unfolded_dir_ids.contains(&entry.id)
&& let Some(root_path) = worktree_snapshot.root_entry()
{
let mut child_entries = worktree_snapshot.child_entries(&entry.path);
if let Some(child) = child_entries.next()
&& entry.path != root_path.path
&& child_entries.next().is_none()
&& child.kind.is_dir()
{
entry_iter.advance();
continue;
}
}
continue;
}
}
let depth = old_ancestors
@ -3074,10 +3066,10 @@ impl ProjectPanel {
.map(|ancestor| ancestor.current_ancestor_depth)
.unwrap_or_default()
.min(auto_folded_ancestors.len());
if let Some(edit_state) = &mut self.edit_state {
if edit_state.entry_id == entry.id {
edit_state.depth = depth;
}
if let Some(edit_state) = &mut self.edit_state
&& edit_state.entry_id == entry.id
{
edit_state.depth = depth;
}
let mut ancestors = std::mem::take(&mut auto_folded_ancestors);
if ancestors.len() > 1 {
@ -3314,11 +3306,10 @@ impl ProjectPanel {
)
})?.await?;
if answer == 1 {
if let Some(item_idx) = paths.iter().position(|p| p == original_path) {
if answer == 1
&& let Some(item_idx) = paths.iter().position(|p| p == original_path) {
paths.remove(item_idx);
}
}
}
if paths.is_empty() {
@ -4309,8 +4300,8 @@ impl ProjectPanel {
}
} else if kind.is_dir() {
project_panel.marked_entries.clear();
if is_sticky {
if let Some((_, _, index)) = project_panel.index_for_entry(entry_id, worktree_id) {
if is_sticky
&& let Some((_, _, index)) = project_panel.index_for_entry(entry_id, worktree_id) {
project_panel.scroll_handle.scroll_to_item_with_offset(index, ScrollStrategy::Top, sticky_index.unwrap_or(0));
cx.notify();
// move down by 1px so that clicked item
@ -4325,7 +4316,6 @@ impl ProjectPanel {
});
return;
}
}
if event.modifiers().alt {
project_panel.toggle_expand_all(entry_id, window, cx);
} else {
@ -4547,15 +4537,14 @@ impl ProjectPanel {
})
})
.on_click(cx.listener(move |this, _, _, cx| {
if index != active_index {
if let Some(folds) =
if index != active_index
&& let Some(folds) =
this.ancestors.get_mut(&entry_id)
{
folds.current_ancestor_depth =
components_len - 1 - index;
cx.notify();
}
}
}))
.child(
Label::new(component)
@ -5034,12 +5023,12 @@ impl ProjectPanel {
'outer: loop {
if let Some(parent_path) = current_path.parent() {
for ancestor_path in parent_path.ancestors() {
if paths.contains(ancestor_path) {
if let Some(parent_entry) = worktree.entry_for_path(ancestor_path) {
sticky_parents.push(parent_entry.clone());
current_path = parent_entry.path.clone();
continue 'outer;
}
if paths.contains(ancestor_path)
&& let Some(parent_entry) = worktree.entry_for_path(ancestor_path)
{
sticky_parents.push(parent_entry.clone());
current_path = parent_entry.path.clone();
continue 'outer;
}
}
}
@ -5291,25 +5280,25 @@ impl Render for ProjectPanel {
.on_action(cx.listener(Self::paste))
.on_action(cx.listener(Self::duplicate))
.on_click(cx.listener(|this, event: &gpui::ClickEvent, window, cx| {
if event.click_count() > 1 {
if let Some(entry_id) = this.last_worktree_root_id {
let project = this.project.read(cx);
if event.click_count() > 1
&& let Some(entry_id) = this.last_worktree_root_id
{
let project = this.project.read(cx);
let worktree_id = if let Some(worktree) =
project.worktree_for_entry(entry_id, cx)
{
worktree.read(cx).id()
} else {
return;
};
let worktree_id = if let Some(worktree) =
project.worktree_for_entry(entry_id, cx)
{
worktree.read(cx).id()
} else {
return;
};
this.selection = Some(SelectedEntry {
worktree_id,
entry_id,
});
this.selection = Some(SelectedEntry {
worktree_id,
entry_id,
});
this.new_file(&NewFile, window, cx);
}
this.new_file(&NewFile, window, cx);
}
}))
})