assistant2: Unify path rendering for file context (#27537)

This ensures that we render path matches the same in both the file
context picker and the messag editor completion provider.

Release Notes:

- N/A
This commit is contained in:
Bennet Bo Fenner 2025-03-28 11:26:54 +01:00 committed by GitHub
parent 7ac51e4c82
commit f6c81a0595
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 92 additions and 141 deletions

View file

@ -273,17 +273,17 @@ pub(crate) fn search_paths(
}
}
pub fn render_file_context_entry(
id: ElementId,
pub fn extract_file_name_and_directory(
path: &Path,
path_prefix: &Arc<str>,
is_directory: bool,
context_store: WeakEntity<ContextStore>,
cx: &App,
) -> Stateful<Div> {
let (file_name, directory) = if path == Path::new("") {
path_prefix: &str,
) -> (SharedString, Option<SharedString>) {
if path == Path::new("") {
(
SharedString::from(path_prefix.trim_end_matches('/').to_string()),
SharedString::from(
path_prefix
.trim_end_matches(std::path::MAIN_SEPARATOR)
.to_string(),
),
None,
)
} else {
@ -294,7 +294,9 @@ pub fn render_file_context_entry(
.to_string()
.into();
let mut directory = path_prefix.to_string();
let mut directory = path_prefix
.trim_end_matches(std::path::MAIN_SEPARATOR)
.to_string();
if !directory.ends_with('/') {
directory.push('/');
}
@ -303,8 +305,19 @@ pub fn render_file_context_entry(
directory.push('/');
}
(file_name, Some(directory))
};
(file_name, Some(directory.into()))
}
}
pub fn render_file_context_entry(
id: ElementId,
path: &Path,
path_prefix: &Arc<str>,
is_directory: bool,
context_store: WeakEntity<ContextStore>,
cx: &App,
) -> Stateful<Div> {
let (file_name, directory) = extract_file_name_and_directory(path, path_prefix);
let added = context_store.upgrade().and_then(|context_store| {
if is_directory {