diff: Render file status in tree

443d96b5964e04f15291467a00ffd127755ffda3
File decorations already supply status markers for file headers. Render
the same marker in the file tree so host review state is visible while
browsing files.

Assisted-by: Codex:gpt-5.5
Alexis Sellier committed ago 1 parent 1309b6a7
crates/diff/src/viewer.rs +7 -2
708 708
    }
709 709
710 710
    /// Renders the file tree.
711 711
    fn render_file_tree(&mut self, area: Rect, buf: &mut Buffer) {
712 712
        let active_file = self.visible_file();
713 -
        self.file_tree
714 -
            .draw(active_file, self.options.diff_palette, area, buf);
713 +
        self.file_tree.draw(
714 +
            active_file,
715 +
            self.options.diff_palette,
716 +
            self.decorator.as_deref(),
717 +
            area,
718 +
            buf,
719 +
        );
715 720
    }
716 721
717 722
    /// Renders the main diff view into `buf`.
718 723
    fn render_diff(&mut self, area: Rect, buf: &mut Buffer) {
719 724
        let body_cols = ScrollView::body_cols(area);
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt +0 -0
src/a.rs +0 -0
src/b.rs +0 -0
README.md +0 -0
src/app/a.rs +0 -0
src/lib/b.rs +0 -0
README.md +0 -0
a.rs +0 -0
b.rs +0 -0
assets/css/style.css +0 -0
assets/css/style.css +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
crates/diff/src/viewer/tree.rs +13 -4
9 9
    TableOptions, Tree, TreeHitZone, TreeModel, TreeNodeKind, TreeRow, TreeState, TreeStyle,
10 10
    Widget,
11 11
};
12 12
13 13
use super::{DiffPalette, FILE_KIND_BADGE_FG, MIN_RENDER_COLS};
14 -
use crate::{DiffDocument, FileId, FileKind, Stats};
14 +
use crate::{DiffDecorator, DiffDocument, FileId, FileKind, Stats};
15 15
16 16
/// Blank rows above the file tree list.
17 17
const TOP_PADDING_ROWS: usize = 1;
18 18
/// Rows reserved for the summary box below the file tree.
19 19
const INFO_BOX_ROWS: usize = 4;
173 173
    /// implementation delegates here using the configured fields.
174 174
    pub(super) fn draw(
175 175
        &mut self,
176 176
        active_file: Option<FileId>,
177 177
        palette: DiffPalette,
178 +
        decorator: Option<&dyn DiffDecorator>,
178 179
        area: Rect,
179 180
        buf: &mut Buffer,
180 181
    ) {
181 182
        let Some((tree_area, info_area)) = Self::areas(area) else {
182 183
            return;
190 191
            model: &self.model,
191 192
            selected: self.state.selected(),
192 193
            active_file,
193 194
            collapsed,
194 195
            palette,
196 +
            decorator,
195 197
        };
196 198
        let tree = Tree::new(&styled, &self.state).style(FILE_TREE_STYLE);
197 199
        let rows = tree.visible_rows();
198 200
        let view = tree.selected_view(&rows, tree_area.rows, Placement::Minimal);
199 201
365 367
366 368
        Size::new(cols, rows).constrain(parent)
367 369
    }
368 370
369 371
    fn render(&mut self, area: Rect, buf: &mut Buffer) {
370 -
        self.draw(self.active_file, self.palette, area, buf);
372 +
        self.draw(self.active_file, self.palette, None, area, buf);
371 373
    }
372 374
}
373 375
374 376
/// Path tree built once from a diff document. Immutable after construction.
375 377
#[derive(Clone, Debug, Eq, PartialEq)]
584 586
    active_file: Option<FileId>,
585 587
    /// Branch ids that are currently collapsed.
586 588
    collapsed: BTreeSet<usize>,
587 589
    /// Positive and negative colors used for file details.
588 590
    palette: DiffPalette,
591 +
    /// Optional host-supplied file decorations.
592 +
    decorator: Option<&'a dyn DiffDecorator>,
589 593
}
590 594
591 595
impl StyledFileTree<'_> {
592 596
    /// Returns whether `id` should render with active styling.
593 597
    ///
657 661
            FileKind::Renamed => FILE_KIND_BADGE_FG,
658 662
            FileKind::Modified | FileKind::Copied | FileKind::ModeChanged | FileKind::Binary => {
659 663
                Color::Yellow
660 664
            }
661 665
        };
666 +
        let status = self
667 +
            .decorator
668 +
            .and_then(|decorator| decorator.file(file.id).status);
669 +
        let marker = status.map_or_else(|| file.kind.marker(), |status| status.item);
670 +
        let marker_style = status.map_or_else(|| Style::new(kind_fg), |status| status.style);
662 671
663 672
        TreeRow::new(Label::new(&node.name).fg(fg))
664 -
            .marker(file.kind.marker())
665 -
            .marker_style(Style::new(kind_fg))
673 +
            .marker(marker)
674 +
            .marker_style(marker_style)
666 675
            .style(self.row_style(id))
667 676
    }
668 677
}
669 678
670 679
#[cfg(test)]
a.rs +0 -0
b.rs +0 -0