fix: formatting and clippy errors

ozer created

Change summary

crates/editor/src/mouse_context_menu.rs   |  6 -
crates/git/src/repository.rs              |  5 +
crates/git_ui/src/commit_view.rs          |  4 
crates/git_ui/src/file_history_view.rs    | 63 ++++++++++----------
crates/git_ui/src/git_ui.rs               | 75 +++++++++++-------------
crates/project/src/git_store.rs           |  6 +-
crates/project_panel/src/project_panel.rs |  3 
7 files changed, 78 insertions(+), 84 deletions(-)

Detailed changes

crates/editor/src/mouse_context_menu.rs 🔗

@@ -265,11 +265,7 @@ pub fn deploy_context_menu(
                     "Copy Permalink",
                     Box::new(CopyPermalinkToLine),
                 )
-                .action_disabled_when(
-                    !has_git_repo,
-                    "File History",
-                    Box::new(git::FileHistory),
-                );
+                .action_disabled_when(!has_git_repo, "File History", Box::new(git::FileHistory));
             match focus {
                 Some(focus) => builder.context(focus),
                 None => builder,

crates/git/src/repository.rs 🔗

@@ -1452,7 +1452,10 @@ impl GitRepository for RealGitRepository {
                         "--no-optional-locks",
                         "log",
                         "--follow",
-                        &format!("--pretty=format:%H%x00%s%x00%B%x00%at%x00%an%x00%ae{}", COMMIT_DELIMITER),
+                        &format!(
+                            "--pretty=format:%H%x00%s%x00%B%x00%at%x00%an%x00%ae{}",
+                            COMMIT_DELIMITER
+                        ),
                         "--",
                     ])
                     .arg(path.as_unix_str())

crates/git_ui/src/commit_view.rs 🔗

@@ -94,12 +94,12 @@ impl CommitView {
                 let (commit_diff, commit_details) = futures::join!(commit_diff?, commit_details?);
                 let mut commit_diff = commit_diff.log_err()?.log_err()?;
                 let commit_details = commit_details.log_err()?.log_err()?;
-                
+
                 // Filter to specific file if requested
                 if let Some(ref filter_path) = file_filter {
                     commit_diff.files.retain(|f| &f.path == filter_path);
                 }
-                
+
                 let repo = repo.upgrade()?;
 
                 workspace

crates/git_ui/src/file_history_view.rs 🔗

@@ -1,13 +1,14 @@
 use anyhow::Result;
-use editor::{Editor, MultiBuffer};
 use git::repository::{FileHistory, FileHistoryEntry, RepoPath};
 use gpui::{
-    actions, uniform_list, App, AnyElement, AnyView, Context, Entity, EventEmitter, FocusHandle,
-    Focusable, IntoElement, ListSizingBehavior, Render, Task, UniformListScrollHandle, WeakEntity,
-    Window, rems,
+    AnyElement, AnyView, App, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
+    ListSizingBehavior, Render, Task, UniformListScrollHandle, WeakEntity, Window, actions, rems,
+    uniform_list,
+};
+use project::{
+    Project, ProjectPath,
+    git_store::{GitStore, Repository},
 };
-use language::Capability;
-use project::{Project, ProjectPath, git_store::{GitStore, Repository}};
 use std::any::{Any, TypeId};
 use time::OffsetDateTime;
 use ui::{Icon, IconName, Label, LabelCommon as _, SharedString, prelude::*};
@@ -24,15 +25,13 @@ actions!(git, [ViewCommitFromHistory]);
 
 pub fn init(cx: &mut App) {
     cx.observe_new(|workspace: &mut Workspace, _window, _cx| {
-        workspace.register_action(|_workspace, _: &ViewCommitFromHistory, _window, _cx| {
-        });
+        workspace.register_action(|_workspace, _: &ViewCommitFromHistory, _window, _cx| {});
     })
     .detach();
 }
 
 pub struct FileHistoryView {
     history: FileHistory,
-    editor: Entity<Editor>,
     repository: WeakEntity<Repository>,
     workspace: WeakEntity<Workspace>,
     selected_entry: Option<usize>,
@@ -98,20 +97,15 @@ impl FileHistoryView {
         history: FileHistory,
         repository: Entity<Repository>,
         workspace: WeakEntity<Workspace>,
-        project: Entity<Project>,
-        window: &mut Window,
+        _project: Entity<Project>,
+        _window: &mut Window,
         cx: &mut Context<Self>,
     ) -> Self {
-        let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadOnly));
-        let editor = cx.new(|cx| {
-            Editor::for_multibuffer(multibuffer.clone(), Some(project.clone()), window, cx)
-        });
         let focus_handle = cx.focus_handle();
         let scroll_handle = UniformListScrollHandle::new();
 
         Self {
             history,
-            editor,
             repository: repository.downgrade(),
             workspace,
             selected_entry: None,
@@ -136,7 +130,7 @@ impl FileHistoryView {
         } else {
             entry.sha.to_string()
         };
-        
+
         let commit_time = OffsetDateTime::from_unix_timestamp(entry.commit_timestamp)
             .unwrap_or_else(|_| OffsetDateTime::UNIX_EPOCH);
         let relative_timestamp = time_format::format_localized_timestamp(
@@ -177,7 +171,7 @@ impl FileHistoryView {
             .on_click(cx.listener(move |this, _, window, cx| {
                 this.selected_entry = Some(ix);
                 cx.notify();
-                
+
                 // Open the commit view filtered to show only this file's changes
                 if let Some(repo) = repo.upgrade() {
                     let sha_str = sha.to_string();
@@ -213,15 +207,12 @@ impl FileHistoryView {
                     .single_line(),
             )
             .child(
-                div()
-                    .flex_none()
-                    .w(rems(6.5))
-                    .child(
-                        Label::new(relative_timestamp)
-                            .size(LabelSize::Small)
-                            .color(ui::Color::Muted)
-                            .single_line(),
-                    ),
+                div().flex_none().w(rems(6.5)).child(
+                    Label::new(relative_timestamp)
+                        .size(LabelSize::Small)
+                        .color(ui::Color::Muted)
+                        .single_line(),
+                ),
             )
             .into_any_element()
     }
@@ -236,7 +227,7 @@ impl Focusable for FileHistoryView {
 }
 
 impl Render for FileHistoryView {
-    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
+    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
         let file_name = self.history.path.file_name().unwrap_or("File");
         let entry_count = self.history.entries.len();
 
@@ -392,7 +383,12 @@ impl Item for FileHistoryView {
         None
     }
 
-    fn added_to_workspace(&mut self, _workspace: &mut Workspace, window: &mut Window, _cx: &mut Context<Self>) {
+    fn added_to_workspace(
+        &mut self,
+        _workspace: &mut Workspace,
+        window: &mut Window,
+        _cx: &mut Context<Self>,
+    ) {
         window.focus(&self.focus_handle);
     }
 
@@ -408,7 +404,13 @@ impl Item for FileHistoryView {
         None
     }
 
-    fn set_nav_history(&mut self, _: workspace::ItemNavHistory, _window: &mut Window, _: &mut Context<Self>) {}
+    fn set_nav_history(
+        &mut self,
+        _: workspace::ItemNavHistory,
+        _window: &mut Window,
+        _: &mut Context<Self>,
+    ) {
+    }
 
     fn act_as_type<'a>(
         &'a self,
@@ -419,4 +421,3 @@ impl Item for FileHistoryView {
         None
     }
 }
-

crates/git_ui/src/git_ui.rs 🔗

@@ -230,48 +230,41 @@ pub fn init(cx: &mut App) {
                 };
             },
         );
-            workspace.register_action(
-                |workspace, _: &git::FileHistory, window, cx| {
-                    let Some(active_item) = workspace.active_item(cx) else {
-                        return;
-                    };
-                    let Some(editor) = active_item.downcast::<Editor>() else {
-                        return;
-                    };
-                    let Some(buffer) = editor
-                        .read(cx)
-                        .buffer()
-                        .read(cx)
-                        .as_singleton()
-                    else {
-                        return;
-                    };
-                    let Some(file) = buffer.read(cx).file() else {
-                        return;
-                    };
-                    let worktree_id = file.worktree_id(cx);
-                    let project_path = ProjectPath {
-                        worktree_id,
-                        path: file.path().clone(),
-                    };
-                    let project = workspace.project();
-                    let git_store = project.read(cx).git_store();
-                    let Some((repo, repo_path)) = git_store
-                        .read(cx)
-                        .repository_and_path_for_project_path(&project_path, cx)
-                    else {
-                        return;
-                    };
-                    file_history_view::FileHistoryView::open(
-                        repo_path,
-                        git_store.downgrade(),
-                        repo.downgrade(),
-                        workspace.weak_handle(),
-                        window,
-                        cx,
-                    );
-                },
+        workspace.register_action(|workspace, _: &git::FileHistory, window, cx| {
+            let Some(active_item) = workspace.active_item(cx) else {
+                return;
+            };
+            let Some(editor) = active_item.downcast::<Editor>() else {
+                return;
+            };
+            let Some(buffer) = editor.read(cx).buffer().read(cx).as_singleton() else {
+                return;
+            };
+            let Some(file) = buffer.read(cx).file() else {
+                return;
+            };
+            let worktree_id = file.worktree_id(cx);
+            let project_path = ProjectPath {
+                worktree_id,
+                path: file.path().clone(),
+            };
+            let project = workspace.project();
+            let git_store = project.read(cx).git_store();
+            let Some((repo, repo_path)) = git_store
+                .read(cx)
+                .repository_and_path_for_project_path(&project_path, cx)
+            else {
+                return;
+            };
+            file_history_view::FileHistoryView::open(
+                repo_path,
+                git_store.downgrade(),
+                repo.downgrade(),
+                workspace.weak_handle(),
+                window,
+                cx,
             );
+        });
     })
     .detach();
 }

crates/project/src/git_store.rs 🔗

@@ -1019,9 +1019,9 @@ impl GitStore {
             repo.send_job(None, move |state, _| async move {
                 match state {
                     RepositoryState::Local { backend, .. } => backend.file_history(path).await,
-                    RepositoryState::Remote { .. } => {
-                        Err(anyhow!("file history not supported for remote repositories yet"))
-                    }
+                    RepositoryState::Remote { .. } => Err(anyhow!(
+                        "file history not supported for remote repositories yet"
+                    )),
                 }
             })
         });

crates/project_panel/src/project_panel.rs 🔗

@@ -1130,7 +1130,8 @@ impl ProjectPanel {
                                 Box::new(zed_actions::workspace::CopyRelativePath),
                             )
                             .when(has_git_repo, |menu| {
-                                menu.separator().action("File History", Box::new(git::FileHistory))
+                                menu.separator()
+                                    .action("File History", Box::new(git::FileHistory))
                             })
                             .when(!should_hide_rename, |menu| {
                                 menu.separator().action("Rename", Box::new(Rename))