From d7efc388e9299dce748d80171ab86633112afae0 Mon Sep 17 00:00:00 2001 From: ozer Date: Tue, 11 Nov 2025 16:27:57 +0300 Subject: [PATCH] fix: formatting and clippy errors --- 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(-) diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index 783e74c70d6b03ea4440a88e6bd0bc0ad76ca093..3a0b698716d120c740bc46d6db0051055cb34124 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/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, diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs index 9c0f91651a05151945ac2f4df12503e846bf03c9..c49d8285cff5ff2864885ba8ee4818a957012e46 100644 --- a/crates/git/src/repository.rs +++ b/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()) diff --git a/crates/git_ui/src/commit_view.rs b/crates/git_ui/src/commit_view.rs index 91babdfc1104a9692395394f555bfd80cd104d38..a74b9ce411bf3b0957f418169db998dd86b30f19 100644 --- a/crates/git_ui/src/commit_view.rs +++ b/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 diff --git a/crates/git_ui/src/file_history_view.rs b/crates/git_ui/src/file_history_view.rs index 88f4a5764628d5367428491388b74e395d6f13c1..bee8d02200dd01311de67fa99f36dedd62d0def5 100644 --- a/crates/git_ui/src/file_history_view.rs +++ b/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, repository: WeakEntity, workspace: WeakEntity, selected_entry: Option, @@ -98,20 +97,15 @@ impl FileHistoryView { history: FileHistory, repository: Entity, workspace: WeakEntity, - project: Entity, - window: &mut Window, + _project: Entity, + _window: &mut Window, cx: &mut Context, ) -> 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) -> impl IntoElement { + fn render(&mut self, _window: &mut Window, cx: &mut Context) -> 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) { + fn added_to_workspace( + &mut self, + _workspace: &mut Workspace, + window: &mut Window, + _cx: &mut Context, + ) { 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) {} + fn set_nav_history( + &mut self, + _: workspace::ItemNavHistory, + _window: &mut Window, + _: &mut Context, + ) { + } fn act_as_type<'a>( &'a self, @@ -419,4 +421,3 @@ impl Item for FileHistoryView { None } } - diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index 186dd702085166bb9760526868fa65426cf58bf7..54adc8130d78e80af5c561541efb8128f1b2a017 100644 --- a/crates/git_ui/src/git_ui.rs +++ b/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::() 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::() 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(); } diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index ca9148885b84ec55763896bdf5aacf0d6dd17593..a9f73bdd608c3bbce4eea563797dd5013d531823 100644 --- a/crates/project/src/git_store.rs +++ b/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" + )), } }) }); diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 0c1576f8257027864c3903dda0ad22b6de1d6143..fae244f919bc6c19aea4381c435989138b78a803 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/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))