mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Refresh open sidebar file previews when files change (#62583)
## Why Sidebar previews load a snapshot of the file when opened, so edits on disk leave the open tab showing stale content. ## What changed Watch each previewed file’s parent directory through the app server so the preview refreshes even when an editor saves by atomically replacing the file. Poll every three seconds when a watch cannot be registered, and resubscribe when reconnecting to the same backend. Preserve the text preview’s reading position across reloads, including when the file temporarily becomes unreadable and then returns. ## Testing The sidebar test covers atomic saves and recovery after moving a directory away and back. It checks that the tab shows updated content at the existing reading position. GitOrigin-RevId: d5f7507d1a81a118fb10a0febf5e274c18f19d81
This commit is contained in:
@@ -217,6 +217,35 @@ impl AppServerFileSystem {
|
||||
.map(drop)
|
||||
}
|
||||
|
||||
pub(crate) async fn watch_document(&self, path: &AppServerPath, id: Uuid) -> Result<()> {
|
||||
// fs/changed notifications use client-native absolute paths. If we can't represent
|
||||
// this directory, don't register a watch whose notifications we can't decode.
|
||||
let path = AbsolutePathBuf::from_absolute_path_checked(path.as_str())?;
|
||||
let _: codex_app_server_protocol::FsWatchResponse = self
|
||||
.request_handle
|
||||
.request_typed(ClientRequest::FsWatch {
|
||||
request_id: RequestId::String(format!("tui-fs-{}", Uuid::new_v4())),
|
||||
params: codex_app_server_protocol::FsWatchParams {
|
||||
watch_id: id.to_string(),
|
||||
path,
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn unwatch_document(&self, id: Uuid) {
|
||||
let _: Result<codex_app_server_protocol::FsUnwatchResponse, _> = self
|
||||
.request_handle
|
||||
.request_typed(ClientRequest::FsUnwatch {
|
||||
request_id: RequestId::String(format!("tui-fs-{}", Uuid::new_v4())),
|
||||
params: codex_app_server_protocol::FsUnwatchParams {
|
||||
watch_id: id.to_string(),
|
||||
},
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn request_fs_path<T: DeserializeOwned>(
|
||||
&self,
|
||||
method: &str,
|
||||
|
||||
@@ -109,6 +109,17 @@ async fn remote_preview_requests_the_source_thread_and_validates_text() -> Resul
|
||||
.unwrap_err();
|
||||
assert!(format!("{error:#}").contains(expected), "{error:#}");
|
||||
}
|
||||
// No fs/watch should reach the server for a path its client can't decode in fs/changed.
|
||||
let foreign = if cfg!(windows) {
|
||||
"/workspace"
|
||||
} else {
|
||||
r"C:\workspace"
|
||||
};
|
||||
let watch = session
|
||||
.file_system()
|
||||
.watch_document(&AppServerPath::from_app_server(foreign), Uuid::new_v4())
|
||||
.await;
|
||||
assert!(watch.is_err());
|
||||
session.shutdown().await?;
|
||||
server.await??;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user