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:
Richard Feldman 2025-03-19 10:59:10 -04:00 committed by GitHub
parent 6303751325
commit e8a40085de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);