diff --git a/crates/assistant2/src/context.rs b/crates/assistant2/src/context.rs index 0f9fc6a3f6..64385352f8 100644 --- a/crates/assistant2/src/context.rs +++ b/crates/assistant2/src/context.rs @@ -156,7 +156,7 @@ impl AssistantContext { impl FileContext { pub fn snapshot(&self, cx: &App) -> Option { let buffer = self.context_buffer.buffer.read(cx); - let path = buffer_path_log_err(buffer)?; + let path = buffer_path_log_err(buffer, cx)?; let full_path: SharedString = path.to_string_lossy().into_owned().into(); let name = match path.file_name() { Some(name) => name.to_string_lossy().into_owned().into(), @@ -231,7 +231,7 @@ impl SymbolContext { pub fn snapshot(&self, cx: &App) -> Option { let buffer = self.context_symbol.buffer.read(cx); let name = self.context_symbol.id.name.clone(); - let path = buffer_path_log_err(buffer)? + let path = buffer_path_log_err(buffer, cx)? .to_string_lossy() .into_owned() .into(); diff --git a/crates/assistant2/src/context_store.rs b/crates/assistant2/src/context_store.rs index 8c6488db63..cf7c582f4c 100644 --- a/crates/assistant2/src/context_store.rs +++ b/crates/assistant2/src/context_store.rs @@ -472,7 +472,7 @@ impl ContextStore { let found_file_context = self.context.iter().find(|context| match &context { AssistantContext::File(file_context) => { let buffer = file_context.context_buffer.buffer.read(cx); - if let Some(file_path) = buffer_path_log_err(buffer) { + if let Some(file_path) = buffer_path_log_err(buffer, cx) { *file_path == *path } else { false @@ -545,7 +545,7 @@ impl ContextStore { .filter_map(|context| match context { AssistantContext::File(file) => { let buffer = file.context_buffer.buffer.read(cx); - buffer_path_log_err(buffer).map(|p| p.to_path_buf()) + buffer_path_log_err(buffer, cx).map(|p| p.to_path_buf()) } AssistantContext::Directory(_) | AssistantContext::Symbol(_) @@ -620,9 +620,14 @@ fn collect_buffer_info_and_text( (buffer_info, text_task) } -pub fn buffer_path_log_err(buffer: &Buffer) -> Option> { +pub fn buffer_path_log_err(buffer: &Buffer, cx: &App) -> Option> { if let Some(file) = buffer.file() { - Some(file.path().clone()) + let mut path = file.path().clone(); + + if path.as_os_str().is_empty() { + path = file.full_path(cx).into(); + } + Some(path) } else { log::error!("Buffer that had a path unexpectedly no longer has a path."); None @@ -708,7 +713,7 @@ pub fn refresh_context_store_text( || changed_buffers.iter().any(|buffer| { let buffer = buffer.read(cx); - buffer_path_log_err(&buffer).map_or(false, |path| { + buffer_path_log_err(&buffer, cx).map_or(false, |path| { path.starts_with(&directory_context.path.path) }) }); @@ -857,7 +862,7 @@ fn refresh_context_buffer( cx: &App, ) -> Option + use<>> { let buffer = context_buffer.buffer.read(cx); - let path = buffer_path_log_err(buffer)?; + let path = buffer_path_log_err(buffer, cx)?; if buffer.version.changed_since(&context_buffer.version) { let (buffer_info, text_task) = collect_buffer_info_and_text( path, @@ -877,7 +882,7 @@ fn refresh_context_symbol( cx: &App, ) -> Option + use<>> { let buffer = context_symbol.buffer.read(cx); - let path = buffer_path_log_err(buffer)?; + let path = buffer_path_log_err(buffer, cx)?; let project_path = buffer.project_path(cx)?; if buffer.version.changed_since(&context_symbol.buffer_version) { let (buffer_info, text_task) = collect_buffer_info_and_text( diff --git a/crates/assistant2/src/context_strip.rs b/crates/assistant2/src/context_strip.rs index d98d131e75..223c340752 100644 --- a/crates/assistant2/src/context_strip.rs +++ b/crates/assistant2/src/context_strip.rs @@ -92,12 +92,12 @@ impl ContextStrip { let active_buffer_entity = editor.buffer().read(cx).as_singleton()?; let active_buffer = active_buffer_entity.read(cx); - let path = active_buffer.file()?.path(); + let path = active_buffer.file()?.full_path(cx); if self .context_store .read(cx) - .will_include_buffer(active_buffer.remote_id(), path) + .will_include_buffer(active_buffer.remote_id(), &path) .is_some() { return None; @@ -108,7 +108,7 @@ impl ContextStrip { None => path.to_string_lossy().into_owned().into(), }; - let icon_path = FileIcons::get_icon(path, cx); + let icon_path = FileIcons::get_icon(&path, cx); Some(SuggestedContext::File { name,