assistant edit tool: Track read buffers and notify model of user edits (#26952)
When the model reads file, we'll track the version it read, and let it know if the user makes edits to the buffer. This helps prevent edit failures because it'll know to re-read the file before. Release Notes: - N/A
This commit is contained in:
parent
cb439e672d
commit
a05066cd83
7 changed files with 83 additions and 23 deletions
|
@ -309,9 +309,7 @@ impl EditToolRequest {
|
|||
}
|
||||
|
||||
self.action_log
|
||||
.update(cx, |log, cx| {
|
||||
log.notify_buffers_changed(self.changed_buffers, cx)
|
||||
})
|
||||
.update(cx, |log, cx| log.buffer_edited(self.changed_buffers, cx))
|
||||
.log_err();
|
||||
|
||||
let errors = self.parser.errors();
|
||||
|
|
|
@ -49,7 +49,7 @@ impl Tool for ReadFileTool {
|
|||
input: serde_json::Value,
|
||||
_messages: &[LanguageModelRequestMessage],
|
||||
project: Entity<Project>,
|
||||
_action_log: Entity<ActionLog>,
|
||||
action_log: Entity<ActionLog>,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<String>> {
|
||||
let input = match serde_json::from_value::<ReadFileToolInput>(input) {
|
||||
|
@ -60,14 +60,15 @@ impl Tool for ReadFileTool {
|
|||
let Some(project_path) = project.read(cx).find_project_path(&input.path, cx) else {
|
||||
return Task::ready(Err(anyhow!("Path not found in project")));
|
||||
};
|
||||
cx.spawn(|cx| async move {
|
||||
|
||||
cx.spawn(|mut cx| async move {
|
||||
let buffer = cx
|
||||
.update(|cx| {
|
||||
project.update(cx, |project, cx| project.open_buffer(project_path, cx))
|
||||
})?
|
||||
.await?;
|
||||
|
||||
buffer.read_with(&cx, |buffer, _cx| {
|
||||
let result = buffer.read_with(&cx, |buffer, _cx| {
|
||||
if buffer
|
||||
.file()
|
||||
.map_or(false, |file| file.disk_state().exists())
|
||||
|
@ -76,7 +77,13 @@ impl Tool for ReadFileTool {
|
|||
} else {
|
||||
Err(anyhow!("File does not exist"))
|
||||
}
|
||||
})?
|
||||
})??;
|
||||
|
||||
action_log.update(&mut cx, |log, cx| {
|
||||
log.buffer_read(buffer, cx);
|
||||
})?;
|
||||
|
||||
anyhow::Ok(result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue