From f060918b578bb3b565adb9daf3a387d40496ca92 Mon Sep 17 00:00:00 2001 From: tidely <43219534+tidely@users.noreply.github.com> Date: Mon, 28 Apr 2025 05:23:37 +0300 Subject: [PATCH] zed: Remove unnecessary clones (#29513) `App::http_client` and `Client::http_client` both return an owned `Arc` which it clones internally. This means we can remove unnecessary clones when calling these methods. Release Notes: - N/A --- crates/agent/src/buffer_codegen.rs | 2 +- crates/agent/src/context_picker/completion_provider.rs | 2 +- crates/agent/src/context_picker/fetch_context_picker.rs | 2 +- crates/assistant/src/inline_assistant.rs | 2 +- crates/assistant_context_editor/src/context_editor.rs | 2 +- crates/assistant_slash_commands/src/docs_command.rs | 2 +- crates/eval/src/eval.rs | 6 +++--- crates/extension_host/src/extension_host.rs | 4 ++-- crates/zed/src/main.rs | 2 +- crates/zed/src/zed.rs | 6 +----- 10 files changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/agent/src/buffer_codegen.rs b/crates/agent/src/buffer_codegen.rs index 4dbadcbaa5..b13270c0b4 100644 --- a/crates/agent/src/buffer_codegen.rs +++ b/crates/agent/src/buffer_codegen.rs @@ -503,7 +503,7 @@ impl CodegenAlternative { } } - let http_client = cx.http_client().clone(); + let http_client = cx.http_client(); let telemetry = self.telemetry.clone(); let language_name = { let multibuffer = self.buffer.read(cx); diff --git a/crates/agent/src/context_picker/completion_provider.rs b/crates/agent/src/context_picker/completion_provider.rs index 05cecc68e7..b5c8bf0248 100644 --- a/crates/agent/src/context_picker/completion_provider.rs +++ b/crates/agent/src/context_picker/completion_provider.rs @@ -708,7 +708,7 @@ impl CompletionProvider for ContextPickerCompletionProvider { let thread_store = self.thread_store.clone(); let editor = self.editor.clone(); - let http_client = workspace.read(cx).client().http_client().clone(); + let http_client = workspace.read(cx).client().http_client(); let MentionCompletion { mode, argument, .. } = state; let query = argument.unwrap_or_else(|| "".to_string()); diff --git a/crates/agent/src/context_picker/fetch_context_picker.rs b/crates/agent/src/context_picker/fetch_context_picker.rs index 5df47e5a28..bd32e44f9b 100644 --- a/crates/agent/src/context_picker/fetch_context_picker.rs +++ b/crates/agent/src/context_picker/fetch_context_picker.rs @@ -193,7 +193,7 @@ impl PickerDelegate for FetchContextPickerDelegate { return; }; - let http_client = workspace.read(cx).client().http_client().clone(); + let http_client = workspace.read(cx).client().http_client(); let url = self.url.clone(); cx.spawn_in(window, async move |this, cx| { let text = cx diff --git a/crates/assistant/src/inline_assistant.rs b/crates/assistant/src/inline_assistant.rs index 85f232fda7..11ef6bd53e 100644 --- a/crates/assistant/src/inline_assistant.rs +++ b/crates/assistant/src/inline_assistant.rs @@ -3023,7 +3023,7 @@ impl CodegenAlternative { } } - let http_client = cx.http_client().clone(); + let http_client = cx.http_client(); let telemetry = self.telemetry.clone(); let language_name = { let multibuffer = self.buffer.read(cx); diff --git a/crates/assistant_context_editor/src/context_editor.rs b/crates/assistant_context_editor/src/context_editor.rs index 522f0f92c6..94e267c85a 100644 --- a/crates/assistant_context_editor/src/context_editor.rs +++ b/crates/assistant_context_editor/src/context_editor.rs @@ -3768,7 +3768,7 @@ pub fn make_lsp_adapter_delegate( let Some(worktree) = project.worktrees(cx).next() else { return Ok(None::>); }; - let http_client = project.client().http_client().clone(); + let http_client = project.client().http_client(); project.lsp_store().update(cx, |_, cx| { Ok(Some(LocalLspAdapterDelegate::new( project.languages().clone(), diff --git a/crates/assistant_slash_commands/src/docs_command.rs b/crates/assistant_slash_commands/src/docs_command.rs index a9d7d1679e..406b433cac 100644 --- a/crates/assistant_slash_commands/src/docs_command.rs +++ b/crates/assistant_slash_commands/src/docs_command.rs @@ -83,7 +83,7 @@ impl DocsSlashCommand { .upgrade() .ok_or_else(|| anyhow!("workspace was dropped"))?; let project = workspace.read(cx).project().clone(); - anyhow::Ok(project.read(cx).client().http_client().clone()) + anyhow::Ok(project.read(cx).client().http_client()) }); if let Some(http_client) = http_client.log_err() { diff --git a/crates/eval/src/eval.rs b/crates/eval/src/eval.rs index f3a9624553..e54a54539e 100644 --- a/crates/eval/src/eval.rs +++ b/crates/eval/src/eval.rs @@ -371,7 +371,7 @@ pub fn init(cx: &mut App) -> Arc { Project::init_settings(cx); let client = Client::production(cx); - cx.set_http_client(client.http_client().clone()); + cx.set_http_client(client.http_client()); let git_binary_path = None; let fs = Arc::new(RealFs::new( @@ -411,7 +411,7 @@ pub fn init(cx: &mut App) -> Arc { tx.send(Some(options)).log_err(); }) .detach(); - let node_runtime = NodeRuntime::new(client.http_client().clone(), rx); + let node_runtime = NodeRuntime::new(client.http_client(), rx); let extension_host_proxy = ExtensionHostProxy::global(cx); @@ -420,7 +420,7 @@ pub fn init(cx: &mut App) -> Arc { language_model::init(client.clone(), cx); language_models::init(user_store.clone(), client.clone(), fs.clone(), cx); languages::init(languages.clone(), node_runtime.clone(), cx); - assistant_tools::init(client.http_client().clone(), cx); + assistant_tools::init(client.http_client(), cx); context_server::init(cx); prompt_store::init(cx); let stdout_is_a_pty = false; diff --git a/crates/extension_host/src/extension_host.rs b/crates/extension_host/src/extension_host.rs index 3be714fc95..411cb23bf1 100644 --- a/crates/extension_host/src/extension_host.rs +++ b/crates/extension_host/src/extension_host.rs @@ -193,8 +193,8 @@ pub fn init( None, extension_host_proxy, fs, - client.http_client().clone(), - client.http_client().clone(), + client.http_client(), + client.http_client(), Some(client.telemetry().clone()), node_runtime, cx, diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 731d12840f..6bf29d964d 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -378,7 +378,7 @@ fn main() { let extension_host_proxy = ExtensionHostProxy::global(cx); let client = Client::production(cx); - cx.set_http_client(client.http_client().clone()); + cx.set_http_client(client.http_client()); let mut languages = LanguageRegistry::new(cx.background_executor().clone()); languages.set_language_server_download_dir(paths::languages_dir().clone()); let languages = Arc::new(languages); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 98c315e996..928d8fd556 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -4245,11 +4245,7 @@ mod tests { project_panel::init(cx); outline_panel::init(cx); terminal_view::init(cx); - copilot::copilot_chat::init( - app_state.fs.clone(), - app_state.client.http_client().clone(), - cx, - ); + copilot::copilot_chat::init(app_state.fs.clone(), app_state.client.http_client(), cx); image_viewer::init(cx); language_model::init(app_state.client.clone(), cx); language_models::init(