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:
Felipe Coury
2026-11-19 20:13:14 +00:00
committed by copyberry
parent 40a848caf4
commit 81ef12b617
12 changed files with 305 additions and 62 deletions
@@ -7,7 +7,21 @@ use ratatui::widgets::Widget;
use super::*;
/// A document can be replaced on disk; retain the offset, not the old rendered cells.
#[derive(Clone, Copy)]
pub(crate) enum DocumentPosition {
Offset(usize),
Latest,
}
impl TranscriptView {
pub(crate) fn document_position(&self) -> DocumentPosition {
match self.position {
Position::Reading(anchor) => DocumentPosition::Offset(anchor.offset),
Position::Latest => DocumentPosition::Latest,
}
}
pub(crate) fn render_document(
&mut self,
area: Rect,