Allow tools to read unsaved buffers (#26987)
If the tool asks to read a path, we don't need to verify whether that path exists on disk; an unsaved buffer with that path is fine. Release Notes: - N/A
This commit is contained in:
@@ -78,29 +78,20 @@ impl Tool for ReadFileTool {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let result = buffer.read_with(cx, |buffer, _cx| {
|
let result = buffer.read_with(cx, |buffer, _cx| {
|
||||||
if buffer
|
let text = buffer.text();
|
||||||
.file()
|
if input.start_line.is_some() || input.end_line.is_some() {
|
||||||
.map_or(false, |file| file.disk_state().exists())
|
let start = input.start_line.unwrap_or(1);
|
||||||
{
|
let lines = text.split('\n').skip(start - 1);
|
||||||
let text = buffer.text();
|
if let Some(end) = input.end_line {
|
||||||
let string = if input.start_line.is_some() || input.end_line.is_some() {
|
let count = end.saturating_sub(start);
|
||||||
let start = input.start_line.unwrap_or(1);
|
Itertools::intersperse(lines.take(count), "\n").collect()
|
||||||
let lines = text.split('\n').skip(start - 1);
|
|
||||||
if let Some(end) = input.end_line {
|
|
||||||
let count = end.saturating_sub(start);
|
|
||||||
Itertools::intersperse(lines.take(count), "\n").collect()
|
|
||||||
} else {
|
|
||||||
Itertools::intersperse(lines, "\n").collect()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
text
|
Itertools::intersperse(lines, "\n").collect()
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(string)
|
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("File does not exist"))
|
text
|
||||||
}
|
}
|
||||||
})??;
|
})?;
|
||||||
|
|
||||||
action_log.update(cx, |log, cx| {
|
action_log.update(cx, |log, cx| {
|
||||||
log.buffer_read(buffer, cx);
|
log.buffer_read(buffer, cx);
|
||||||
|
|||||||
Reference in New Issue
Block a user