One big cleanup pass of clippy lints
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
e7540d2833
commit
8ba2f77148
138 changed files with 1328 additions and 1366 deletions
|
@ -189,7 +189,7 @@ pub struct NavigationEntry {
|
|||
impl Pane {
|
||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
let handle = cx.weak_handle();
|
||||
let context_menu = cx.add_view(|cx| ContextMenu::new(cx));
|
||||
let context_menu = cx.add_view(ContextMenu::new);
|
||||
Self {
|
||||
items: Vec::new(),
|
||||
is_active: true,
|
||||
|
@ -389,7 +389,7 @@ impl Pane {
|
|||
let existing_item = pane.update(cx, |pane, cx| {
|
||||
for (ix, item) in pane.items.iter().enumerate() {
|
||||
if item.project_path(cx).is_some()
|
||||
&& item.project_entry_ids(cx).as_slice() == &[project_entry_id]
|
||||
&& item.project_entry_ids(cx).as_slice() == [project_entry_id]
|
||||
{
|
||||
let item = item.boxed_clone();
|
||||
pane.activate_item(ix, true, focus_item, true, cx);
|
||||
|
@ -450,7 +450,7 @@ impl Pane {
|
|||
self.items.iter()
|
||||
}
|
||||
|
||||
pub fn items_of_type<'a, T: View>(&'a self) -> impl 'a + Iterator<Item = ViewHandle<T>> {
|
||||
pub fn items_of_type<T: View>(&self) -> impl '_ + Iterator<Item = ViewHandle<T>> {
|
||||
self.items
|
||||
.iter()
|
||||
.filter_map(|item| item.to_any().downcast())
|
||||
|
@ -466,7 +466,7 @@ impl Pane {
|
|||
cx: &AppContext,
|
||||
) -> Option<Box<dyn ItemHandle>> {
|
||||
self.items.iter().find_map(|item| {
|
||||
if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == &[entry_id] {
|
||||
if item.is_singleton(cx) && item.project_entry_ids(cx).as_slice() == [entry_id] {
|
||||
Some(item.boxed_clone())
|
||||
} else {
|
||||
None
|
||||
|
@ -532,7 +532,7 @@ impl Pane {
|
|||
let mut index = self.active_item_index;
|
||||
if index > 0 {
|
||||
index -= 1;
|
||||
} else if self.items.len() > 0 {
|
||||
} else if !self.items.is_empty() {
|
||||
index = self.items.len() - 1;
|
||||
}
|
||||
self.activate_item(index, true, true, false, cx);
|
||||
|
@ -653,7 +653,7 @@ impl Pane {
|
|||
{
|
||||
let other_project_entry_ids = item.project_entry_ids(cx);
|
||||
project_entry_ids
|
||||
.retain(|id| !other_project_entry_ids.contains(&id));
|
||||
.retain(|id| !other_project_entry_ids.contains(id));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -662,12 +662,11 @@ impl Pane {
|
|||
.any(|id| saved_project_entry_ids.insert(*id))
|
||||
};
|
||||
|
||||
if should_save {
|
||||
if !Self::save_item(project.clone(), &pane, item_ix, &item, true, &mut cx)
|
||||
if should_save
|
||||
&& !Self::save_item(project.clone(), &pane, item_ix, &*item, true, &mut cx)
|
||||
.await?
|
||||
{
|
||||
break;
|
||||
}
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Remove the item from the pane.
|
||||
|
@ -728,14 +727,13 @@ impl Pane {
|
|||
project: ModelHandle<Project>,
|
||||
pane: &ViewHandle<Pane>,
|
||||
item_ix: usize,
|
||||
item: &Box<dyn ItemHandle>,
|
||||
item: &dyn ItemHandle,
|
||||
should_prompt_for_save: bool,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<bool> {
|
||||
const CONFLICT_MESSAGE: &'static str =
|
||||
const CONFLICT_MESSAGE: &str =
|
||||
"This file has changed on disk since you started editing it. Do you want to overwrite it?";
|
||||
const DIRTY_MESSAGE: &'static str =
|
||||
"This file contains unsaved edits. Do you want to save it?";
|
||||
const DIRTY_MESSAGE: &str = "This file contains unsaved edits. Do you want to save it?";
|
||||
|
||||
let (has_conflict, is_dirty, can_save, is_singleton) = cx.read(|cx| {
|
||||
(
|
||||
|
@ -765,7 +763,7 @@ impl Pane {
|
|||
matches!(
|
||||
cx.global::<Settings>().autosave,
|
||||
Autosave::OnFocusChange | Autosave::OnWindowChange
|
||||
) && Self::can_autosave_item(item.as_ref(), cx)
|
||||
) && Self::can_autosave_item(&*item, cx)
|
||||
});
|
||||
let should_save = if should_prompt_for_save && !will_autosave {
|
||||
let mut answer = pane.update(cx, |pane, cx| {
|
||||
|
@ -794,7 +792,7 @@ impl Pane {
|
|||
let worktree = project.visible_worktrees(cx).next()?;
|
||||
Some(worktree.read(cx).as_local()?.abs_path().to_path_buf())
|
||||
})
|
||||
.unwrap_or(Path::new("").into());
|
||||
.unwrap_or_else(|| Path::new("").into());
|
||||
|
||||
let mut abs_path = cx.update(|cx| cx.prompt_for_new_path(&start_abs_path));
|
||||
if let Some(abs_path) = abs_path.next().await.flatten() {
|
||||
|
|
|
@ -50,7 +50,7 @@ impl PaneGroup {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn render<'a>(
|
||||
pub(crate) fn render(
|
||||
&self,
|
||||
theme: &Theme,
|
||||
follower_states: &FollowerStatesByLeader,
|
||||
|
|
|
@ -38,7 +38,7 @@ where
|
|||
}
|
||||
|
||||
fn is_focused(&self, cx: &AppContext) -> bool {
|
||||
ViewHandle::is_focused(&self, cx) || self.read(cx).contains_focused_view(cx)
|
||||
ViewHandle::is_focused(self, cx) || self.read(cx).contains_focused_view(cx)
|
||||
}
|
||||
|
||||
fn to_any(&self) -> AnyViewHandle {
|
||||
|
@ -46,9 +46,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<AnyViewHandle> for &dyn SidebarItemHandle {
|
||||
fn into(self) -> AnyViewHandle {
|
||||
self.to_any()
|
||||
impl From<&dyn SidebarItemHandle> for AnyViewHandle {
|
||||
fn from(val: &dyn SidebarItemHandle) -> Self {
|
||||
val.to_any()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,11 +284,14 @@ impl View for SidebarButtons {
|
|||
Side::Left => theme.group_left,
|
||||
Side::Right => theme.group_right,
|
||||
};
|
||||
|
||||
#[allow(clippy::needless_collect)]
|
||||
let items = sidebar
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| (item.icon_path, item.tooltip.clone(), item.view.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Flex::row()
|
||||
.with_children(items.into_iter().enumerate().map(
|
||||
|(ix, (icon_path, tooltip, item_view))| {
|
||||
|
|
|
@ -126,8 +126,8 @@ impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<AnyViewHandle> for &dyn StatusItemViewHandle {
|
||||
fn into(self) -> AnyViewHandle {
|
||||
self.to_any()
|
||||
impl From<&dyn StatusItemViewHandle> for AnyViewHandle {
|
||||
fn from(val: &dyn StatusItemViewHandle) -> Self {
|
||||
val.to_any()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,12 +133,10 @@ impl View for Toolbar {
|
|||
.with_child(nav_button(
|
||||
"icons/arrow_right_16.svg",
|
||||
button_style,
|
||||
tooltip_style.clone(),
|
||||
tooltip_style,
|
||||
enable_go_forward,
|
||||
spacing,
|
||||
super::GoForward {
|
||||
pane: Some(pane.clone()),
|
||||
},
|
||||
super::GoForward { pane: Some(pane) },
|
||||
super::GoForward { pane: None },
|
||||
"Go Forward",
|
||||
cx,
|
||||
|
@ -156,6 +154,7 @@ impl View for Toolbar {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn nav_button<A: Action + Clone>(
|
||||
svg_path: &'static str,
|
||||
style: theme::Interactive<theme::IconButton>,
|
||||
|
@ -280,8 +279,8 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<AnyViewHandle> for &dyn ToolbarItemViewHandle {
|
||||
fn into(self) -> AnyViewHandle {
|
||||
self.to_any()
|
||||
impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle {
|
||||
fn from(val: &dyn ToolbarItemViewHandle) -> Self {
|
||||
val.to_any()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ impl WaitingRoom {
|
|||
workspace
|
||||
});
|
||||
}
|
||||
Err(error @ _) => {
|
||||
Err(error) => {
|
||||
let login = &contact.user.github_login;
|
||||
let message = match error {
|
||||
project::JoinProjectError::HostDeclined => {
|
||||
|
|
|
@ -588,7 +588,9 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
|
||||
if T::is_edit_event(event) {
|
||||
if let Autosave::AfterDelay { milliseconds } = cx.global::<Settings>().autosave {
|
||||
let prev_autosave = pending_autosave.take().unwrap_or(Task::ready(Some(())));
|
||||
let prev_autosave = pending_autosave
|
||||
.take()
|
||||
.unwrap_or_else(|| Task::ready(Some(())));
|
||||
let (cancel_tx, mut cancel_rx) = oneshot::channel::<()>();
|
||||
let prev_cancel_tx = mem::replace(&mut cancel_pending_autosave, cancel_tx);
|
||||
let project = workspace.project.downgrade();
|
||||
|
@ -695,9 +697,9 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<AnyViewHandle> for Box<dyn ItemHandle> {
|
||||
fn into(self) -> AnyViewHandle {
|
||||
self.to_any()
|
||||
impl From<Box<dyn ItemHandle>> for AnyViewHandle {
|
||||
fn from(val: Box<dyn ItemHandle>) -> Self {
|
||||
val.to_any()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -742,9 +744,9 @@ impl<T: Notification> NotificationHandle for ViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<AnyViewHandle> for &dyn NotificationHandle {
|
||||
fn into(self) -> AnyViewHandle {
|
||||
self.to_any()
|
||||
impl From<&dyn NotificationHandle> for AnyViewHandle {
|
||||
fn from(val: &dyn NotificationHandle) -> Self {
|
||||
val.to_any()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -769,7 +771,7 @@ impl AppState {
|
|||
user_store,
|
||||
project_store,
|
||||
initialize_workspace: |_, _, _| {},
|
||||
build_window_options: || Default::default(),
|
||||
build_window_options: Default::default,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -848,7 +850,7 @@ impl Workspace {
|
|||
})
|
||||
.detach();
|
||||
|
||||
let pane = cx.add_view(|cx| Pane::new(cx));
|
||||
let pane = cx.add_view(Pane::new);
|
||||
let pane_id = pane.id();
|
||||
cx.subscribe(&pane, move |this, _, event, cx| {
|
||||
this.handle_pane_event(pane_id, event, cx)
|
||||
|
@ -860,8 +862,8 @@ impl Workspace {
|
|||
let fs = project.read(cx).fs().clone();
|
||||
let user_store = project.read(cx).user_store();
|
||||
let client = project.read(cx).client();
|
||||
let mut current_user = user_store.read(cx).watch_current_user().clone();
|
||||
let mut connection_status = client.status().clone();
|
||||
let mut current_user = user_store.read(cx).watch_current_user();
|
||||
let mut connection_status = client.status();
|
||||
let _observe_current_user = cx.spawn_weak(|this, mut cx| async move {
|
||||
current_user.recv().await;
|
||||
connection_status.recv().await;
|
||||
|
@ -1073,7 +1075,7 @@ impl Workspace {
|
|||
project.clone(),
|
||||
&pane,
|
||||
ix,
|
||||
&item,
|
||||
&*item,
|
||||
should_prompt_to_save,
|
||||
&mut cx,
|
||||
)
|
||||
|
@ -1088,6 +1090,7 @@ impl Workspace {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn open_paths(
|
||||
&mut self,
|
||||
mut abs_paths: Vec<PathBuf>,
|
||||
|
@ -1150,10 +1153,8 @@ impl Workspace {
|
|||
let results = this
|
||||
.update(&mut cx, |this, cx| this.open_paths(paths, true, cx))
|
||||
.await;
|
||||
for result in results {
|
||||
if let Some(result) = result {
|
||||
result.log_err();
|
||||
}
|
||||
for result in results.into_iter().flatten() {
|
||||
result.log_err();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -1316,7 +1317,7 @@ impl Workspace {
|
|||
if let Some(item) = self.active_item(cx) {
|
||||
if !force_name_change && item.can_save(cx) {
|
||||
if item.has_conflict(cx.as_ref()) {
|
||||
const CONFLICT_MESSAGE: &'static str = "This file has changed on disk since you started editing it. Do you want to overwrite it?";
|
||||
const CONFLICT_MESSAGE: &str = "This file has changed on disk since you started editing it. Do you want to overwrite it?";
|
||||
|
||||
let mut answer = cx.prompt(
|
||||
PromptLevel::Warning,
|
||||
|
@ -1424,7 +1425,7 @@ impl Workspace {
|
|||
}
|
||||
|
||||
fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> ViewHandle<Pane> {
|
||||
let pane = cx.add_view(|cx| Pane::new(cx));
|
||||
let pane = cx.add_view(Pane::new);
|
||||
let pane_id = pane.id();
|
||||
cx.subscribe(&pane, move |this, _, event, cx| {
|
||||
this.handle_pane_event(pane_id, event, cx)
|
||||
|
@ -1519,11 +1520,9 @@ impl Workspace {
|
|||
|
||||
pub fn activate_item(&mut self, item: &dyn ItemHandle, cx: &mut ViewContext<Self>) -> bool {
|
||||
let result = self.panes.iter().find_map(|pane| {
|
||||
if let Some(ix) = pane.read(cx).index_for_item(item) {
|
||||
Some((pane.clone(), ix))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
pane.read(cx)
|
||||
.index_for_item(item)
|
||||
.map(|ix| (pane.clone(), ix))
|
||||
});
|
||||
if let Some((pane, ix)) = result {
|
||||
pane.update(cx, |pane, cx| pane.activate_item(ix, true, true, false, cx));
|
||||
|
@ -1749,7 +1748,7 @@ impl Workspace {
|
|||
let collaborators = self.project.read(cx).collaborators();
|
||||
let next_leader_id = if let Some(leader_id) = self.leader_for_pane(&self.active_pane) {
|
||||
let mut collaborators = collaborators.keys().copied();
|
||||
while let Some(peer_id) = collaborators.next() {
|
||||
for peer_id in collaborators.by_ref() {
|
||||
if peer_id == leader_id {
|
||||
break;
|
||||
}
|
||||
|
@ -1779,7 +1778,7 @@ impl Workspace {
|
|||
) -> Option<PeerId> {
|
||||
for (leader_id, states_by_pane) in &mut self.follower_states_by_leader {
|
||||
let leader_id = *leader_id;
|
||||
if let Some(state) = states_by_pane.remove(&pane) {
|
||||
if let Some(state) = states_by_pane.remove(pane) {
|
||||
for (_, item) in state.items_by_leader_view_id {
|
||||
if let FollowerItem::Loaded(item) = item {
|
||||
item.set_leader_replica_id(None, cx);
|
||||
|
@ -2253,7 +2252,6 @@ impl Workspace {
|
|||
.values()
|
||||
.map(|b| b.0)
|
||||
.collect::<Vec<_>>()
|
||||
.clone()
|
||||
});
|
||||
|
||||
let mut item_tasks_by_pane = HashMap::default();
|
||||
|
@ -2367,13 +2365,11 @@ impl Workspace {
|
|||
fn leader_updated(&mut self, leader_id: PeerId, cx: &mut ViewContext<Self>) -> Option<()> {
|
||||
let mut items_to_add = Vec::new();
|
||||
for (pane, state) in self.follower_states_by_leader.get(&leader_id)? {
|
||||
if let Some(active_item) = state
|
||||
if let Some(FollowerItem::Loaded(item)) = state
|
||||
.active_view_id
|
||||
.and_then(|id| state.items_by_leader_view_id.get(&id))
|
||||
{
|
||||
if let FollowerItem::Loaded(item) = active_item {
|
||||
items_to_add.push((pane.clone(), item.boxed_clone()));
|
||||
}
|
||||
items_to_add.push((pane.clone(), item.boxed_clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2626,6 +2622,7 @@ pub fn activate_workspace_for_project(
|
|||
None
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn open_paths(
|
||||
abs_paths: &[PathBuf],
|
||||
app_state: &Arc<AppState>,
|
||||
|
@ -2914,7 +2911,7 @@ mod tests {
|
|||
let item1 = cx.add_view(&workspace, |_| TestItem::new());
|
||||
workspace.update(cx, |w, cx| w.add_item(Box::new(item1.clone()), cx));
|
||||
let task = workspace.update(cx, |w, cx| w.prepare_to_close(cx));
|
||||
assert_eq!(task.await.unwrap(), true);
|
||||
assert!(task.await.unwrap());
|
||||
|
||||
// When there are dirty untitled items, prompt to save each one. If the user
|
||||
// cancels any prompt, then abort.
|
||||
|
@ -2938,7 +2935,7 @@ mod tests {
|
|||
cx.simulate_prompt_answer(window_id, 2 /* cancel */);
|
||||
cx.foreground().run_until_parked();
|
||||
assert!(!cx.has_pending_prompt(window_id));
|
||||
assert_eq!(task.await.unwrap(), false);
|
||||
assert!(!task.await.unwrap());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
@ -3396,7 +3393,7 @@ mod tests {
|
|||
impl Item for TestItem {
|
||||
fn tab_description<'a>(&'a self, detail: usize, _: &'a AppContext) -> Option<Cow<'a, str>> {
|
||||
self.tab_descriptions.as_ref().and_then(|descriptions| {
|
||||
let description = *descriptions.get(detail).or(descriptions.last())?;
|
||||
let description = *descriptions.get(detail).or_else(|| descriptions.last())?;
|
||||
Some(description.into())
|
||||
})
|
||||
}
|
||||
|
@ -3452,7 +3449,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn can_save(&self, _: &AppContext) -> bool {
|
||||
self.project_entry_ids.len() > 0
|
||||
!self.project_entry_ids.is_empty()
|
||||
}
|
||||
|
||||
fn save(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue