assistant2: Handle non-text files in context pickers (#22795)

We'll now show an error message if the user tries to add a directory
that contains no text files or when they try to add a single non-text
file.

Release Notes:

- N/A

---------

Co-authored-by: Danilo <danilo@zed.dev>
This commit is contained in:
Agus Zubiaga 2025-01-08 11:06:29 -03:00 committed by GitHub
parent 52f29b4a1f
commit 36301442dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 25 deletions

View file

@ -239,21 +239,34 @@ impl PickerDelegate for FileContextPickerDelegate {
return anyhow::Ok(());
};
let buffer = open_buffer_task.await?;
let result = open_buffer_task.await;
this.update(&mut cx, |this, cx| {
this.delegate
.context_store
.update(cx, |context_store, cx| {
context_store.insert_file(buffer.read(cx));
})?;
this.update(&mut cx, |this, cx| match result {
Ok(buffer) => {
this.delegate
.context_store
.update(cx, |context_store, cx| {
context_store.insert_file(buffer.read(cx));
})?;
match confirm_behavior {
ConfirmBehavior::KeepOpen => {}
ConfirmBehavior::Close => this.delegate.dismissed(cx),
match confirm_behavior {
ConfirmBehavior::KeepOpen => {}
ConfirmBehavior::Close => this.delegate.dismissed(cx),
}
anyhow::Ok(())
}
Err(err) => {
let Some(workspace) = workspace.upgrade() else {
return anyhow::Ok(());
};
anyhow::Ok(())
workspace.update(cx, |workspace, cx| {
workspace.show_error(&err, cx);
});
anyhow::Ok(())
}
})??;
anyhow::Ok(())