Return which files were touched in the edit tool (#26564)
<img width="631" alt="Screenshot 2025-03-12 at 12 56 43 PM" src="https://github.com/user-attachments/assets/9ab84a53-829a-4943-ae76-b1d97ee31f55" /> <img width="908" alt="Screenshot 2025-03-12 at 12 57 12 PM" src="https://github.com/user-attachments/assets/bd246231-6c92-4266-b61e-5293adfe2ba0" /> Release Notes: - N/A
This commit is contained in:
parent
3ec323ce0d
commit
3131b0459f
1 changed files with 15 additions and 2 deletions
|
@ -12,6 +12,7 @@ use language_model::{
|
||||||
use project::{Project, ProjectPath};
|
use project::{Project, ProjectPath};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt::Write;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
|
@ -145,17 +146,29 @@ impl Tool for EditFilesTool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut answer = match changed_buffers.len() {
|
||||||
|
0 => "No files were edited.".to_string(),
|
||||||
|
1 => "Successfully edited ".to_string(),
|
||||||
|
_ => "Successfully edited these files:\n\n".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
// Save each buffer once at the end
|
// Save each buffer once at the end
|
||||||
for buffer in changed_buffers {
|
for buffer in changed_buffers {
|
||||||
project
|
project
|
||||||
.update(&mut cx, |project, cx| project.save_buffer(buffer, cx))?
|
.update(&mut cx, |project, cx| {
|
||||||
|
if let Some(file) = buffer.read(&cx).file() {
|
||||||
|
let _ = write!(&mut answer, "{}\n\n", &file.path().display());
|
||||||
|
}
|
||||||
|
|
||||||
|
project.save_buffer(buffer, cx)
|
||||||
|
})?
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let errors = parser.errors();
|
let errors = parser.errors();
|
||||||
|
|
||||||
if errors.is_empty() {
|
if errors.is_empty() {
|
||||||
Ok("Successfully applied all edits".into())
|
Ok(answer.trim_end().to_string())
|
||||||
} else {
|
} else {
|
||||||
let error_message = errors
|
let error_message = errors
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue