chore: Fix several style lints (#17488)

It's not comprehensive enough to start linting on `style` group, but
hey, it's a start.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-09-06 11:58:39 +02:00 committed by GitHub
parent 93249fc82b
commit e6c1c51b37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
361 changed files with 3530 additions and 3587 deletions

View file

@ -484,10 +484,8 @@ impl Pane {
.find_position(|item| item.item_id() == alternative.id());
if let Some((ix, _)) = existing {
self.activate_item(ix, true, true, cx);
} else {
if let Some(upgraded) = alternative.upgrade() {
self.add_item(upgraded, true, true, None, cx);
}
} else if let Some(upgraded) = alternative.upgrade() {
self.add_item(upgraded, true, true, None, cx);
}
}
}
@ -781,9 +779,7 @@ impl Pane {
}
pub fn close_current_preview_item(&mut self, cx: &mut ViewContext<Self>) -> Option<usize> {
let Some(item_idx) = self.preview_item_idx() else {
return None;
};
let item_idx = self.preview_item_idx()?;
let prev_active_item_index = self.active_item_index;
self.remove_item(item_idx, false, false, cx);
@ -805,7 +801,7 @@ impl Pane {
cx: &mut ViewContext<Self>,
) {
if item.is_singleton(cx) {
if let Some(&entry_id) = item.project_entry_ids(cx).get(0) {
if let Some(&entry_id) = item.project_entry_ids(cx).first() {
let project = self.project.read(cx);
if let Some(project_path) = project.path_for_entry(entry_id, cx) {
let abs_path = project.absolute_path(&project_path, cx);
@ -831,7 +827,7 @@ impl Pane {
// Does the item already exist?
let project_entry_id = if item.is_singleton(cx) {
item.project_entry_ids(cx).get(0).copied()
item.project_entry_ids(cx).first().copied()
} else {
None
};
@ -842,7 +838,7 @@ impl Pane {
} else if existing_item.is_singleton(cx) {
existing_item
.project_entry_ids(cx)
.get(0)
.first()
.map_or(false, |existing_entry_id| {
Some(existing_entry_id) == project_entry_id.as_ref()
})
@ -1600,12 +1596,10 @@ impl Pane {
project: Model<Project>,
cx: &mut WindowContext,
) -> Task<Result<()>> {
let format =
if let AutosaveSetting::AfterDelay { .. } = item.workspace_settings(cx).autosave {
false
} else {
true
};
let format = !matches!(
item.workspace_settings(cx).autosave,
AutosaveSetting::AfterDelay { .. }
);
if Self::can_autosave_item(item, cx) {
item.save(format, project, cx)
} else {
@ -1817,7 +1811,7 @@ impl Pane {
let icon_color = if ItemSettings::get_global(cx).git_status {
project_path
.as_ref()
.and_then(|path| self.project.read(cx).entry_for_path(&path, cx))
.and_then(|path| self.project.read(cx).entry_for_path(path, cx))
.map(|entry| {
Self::git_aware_icon_color(entry.git_status, entry.is_ignored, is_active)
})
@ -2458,20 +2452,17 @@ impl Pane {
split_direction = None;
}
if let Some(open_task) = workspace
.update(&mut cx, |workspace, cx| {
if let Some(split_direction) = split_direction {
to_pane = workspace.split_pane(to_pane, split_direction, cx);
}
workspace.open_paths(
paths,
OpenVisible::OnlyDirectories,
Some(to_pane.downgrade()),
cx,
)
})
.ok()
{
if let Ok(open_task) = workspace.update(&mut cx, |workspace, cx| {
if let Some(split_direction) = split_direction {
to_pane = workspace.split_pane(to_pane, split_direction, cx);
}
workspace.open_paths(
paths,
OpenVisible::OnlyDirectories,
Some(to_pane.downgrade()),
cx,
)
}) {
let opened_items: Vec<_> = open_task.await;
_ = workspace.update(&mut cx, |workspace, cx| {
for item in opened_items.into_iter().flatten() {
@ -2887,14 +2878,14 @@ fn dirty_message_for(buffer_path: Option<ProjectPath>) -> String {
.and_then(|p| {
p.path
.to_str()
.and_then(|s| if s == "" { None } else { Some(s) })
.and_then(|s| if s.is_empty() { None } else { Some(s) })
})
.unwrap_or("This buffer");
let path = truncate_and_remove_front(path, 80);
format!("{path} contains unsaved edits. Do you want to save it?")
}
pub fn tab_details(items: &Vec<Box<dyn ItemHandle>>, cx: &AppContext) -> Vec<usize> {
pub fn tab_details(items: &[Box<dyn ItemHandle>], cx: &AppContext) -> Vec<usize> {
let mut tab_details = items.iter().map(|_| 0).collect::<Vec<_>>();
let mut tab_descriptions = HashMap::default();
let mut done = false;
@ -2942,6 +2933,25 @@ pub fn render_item_indicator(item: Box<dyn ItemHandle>, cx: &WindowContext) -> O
})
}
impl Render for DraggedTab {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let ui_font = ThemeSettings::get_global(cx).ui_font.clone();
let label = self.item.tab_content(
TabContentParams {
detail: Some(self.detail),
selected: false,
preview: false,
},
cx,
);
Tab::new("")
.selected(self.is_active)
.child(label)
.render(cx)
.font(ui_font)
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -3484,22 +3494,3 @@ mod tests {
})
}
}
impl Render for DraggedTab {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let ui_font = ThemeSettings::get_global(cx).ui_font.clone();
let label = self.item.tab_content(
TabContentParams {
detail: Some(self.detail),
selected: false,
preview: false,
},
cx,
);
Tab::new("")
.selected(self.is_active)
.child(label)
.render(cx)
.font(ui_font)
}
}