From 690ad29ba9461817274c388ab4122bf9152b0c10 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Fri, 10 Jan 2025 02:20:15 -0700 Subject: [PATCH] assistant2: Small misc efficiency improvements (#22947) Release Notes: - N/A --- crates/assistant2/src/context_store.rs | 26 ++++++++++++-------------- crates/language_model/src/request.rs | 4 ++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/crates/assistant2/src/context_store.rs b/crates/assistant2/src/context_store.rs index 66f4a7eace..2660a0e9bc 100644 --- a/crates/assistant2/src/context_store.rs +++ b/crates/assistant2/src/context_store.rs @@ -191,22 +191,20 @@ impl ContextStore { collect_files_in_path(worktree, &project_path.path) })?; - let open_buffer_tasks = project.update(&mut cx, |project, cx| { - files - .iter() - .map(|file_path| { - project.open_buffer( - ProjectPath { - worktree_id, - path: file_path.clone(), - }, - cx, - ) - }) - .collect::>() + let open_buffers_task = project.update(&mut cx, |project, cx| { + let tasks = files.iter().map(|file_path| { + project.open_buffer( + ProjectPath { + worktree_id, + path: file_path.clone(), + }, + cx, + ) + }); + future::join_all(tasks) })?; - let buffers = future::join_all(open_buffer_tasks).await; + let buffers = open_buffers_task.await; let mut buffer_infos = Vec::new(); let mut text_tasks = Vec::new(); diff --git a/crates/language_model/src/request.rs b/crates/language_model/src/request.rs index e6f7f210c7..513f51f286 100644 --- a/crates/language_model/src/request.rs +++ b/crates/language_model/src/request.rs @@ -214,9 +214,9 @@ impl LanguageModelRequestMessage { .content .first() .map(|content| match content { - MessageContent::Text(text) => text.trim().is_empty(), + MessageContent::Text(text) => text.chars().all(|c| c.is_whitespace()), MessageContent::ToolResult(tool_result) => { - tool_result.content.trim().is_empty() + tool_result.content.chars().all(|c| c.is_whitespace()) } MessageContent::ToolUse(_) | MessageContent::Image(_) => true, })