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:
parent
6303751325
commit
e8a40085de
1 changed files with 11 additions and 20 deletions
|
@ -78,12 +78,8 @@ impl Tool for ReadFileTool {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let result = 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())
|
|
||||||
{
|
|
||||||
let text = buffer.text();
|
let text = buffer.text();
|
||||||
let string = if input.start_line.is_some() || input.end_line.is_some() {
|
if input.start_line.is_some() || input.end_line.is_some() {
|
||||||
let start = input.start_line.unwrap_or(1);
|
let start = input.start_line.unwrap_or(1);
|
||||||
let lines = text.split('\n').skip(start - 1);
|
let lines = text.split('\n').skip(start - 1);
|
||||||
if let Some(end) = input.end_line {
|
if let Some(end) = input.end_line {
|
||||||
|
@ -94,13 +90,8 @@ impl Tool for ReadFileTool {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text
|
text
|
||||||
};
|
|
||||||
|
|
||||||
Ok(string)
|
|
||||||
} else {
|
|
||||||
Err(anyhow!("File does not exist"))
|
|
||||||
}
|
}
|
||||||
})??;
|
})?;
|
||||||
|
|
||||||
action_log.update(cx, |log, cx| {
|
action_log.update(cx, |log, cx| {
|
||||||
log.buffer_read(buffer, cx);
|
log.buffer_read(buffer, cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue