Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions crates/disktree-app/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,51 @@ fn escape_cancels_the_first_scan_and_r_starts_it_again(
assert!(read(&view, cx, |app| app.tree().is_some()));
}

/// A scan that failed leaves no walk and no tree, so the panel must not go
/// on spinning as if one were coming, nor call a failure a cancellation.
#[gpui_kit::test]
fn a_scan_that_failed_says_so_instead_of_spinning(cx: &mut TestAppContext) {
cx.update(gpui_omarchy::init);
let temp = fixture();
// Nothing is there to read, which is the plainest way a scan fails.
let root = temp.path().join("gone");
let (view, cx) =
cx.add_window_view(move |_, cx| Disktree::new(root, options(), 3, cx));
draw(cx);
assert!(cx.debug_bounds("scan-reading").is_some());
assert!(cx.debug_bounds("scan-meter").is_some());
assert!(cx.debug_bounds("insights-waiting").is_some());

let epoch = read(&view, cx, |app| app.scan_epoch);
// Six seconds at most, as `finish_scan` allows a scan that lands.
for _ in 0..600 {
std::thread::sleep(std::time::Duration::from_millis(5));
if !update(&view, cx, |app, cx| app.poll_scan_once(epoch, cx)) {
break;
}
}
let (scanning, error, cancelled) = read(&view, cx, |app| {
(
app.scan.is_some(),
app.scan_error.is_some(),
app.progress.cancelled,
)
});
assert!(!scanning, "the scan never ended");
assert!(error, "a root that is not there cannot be read");
assert!(!cancelled, "nobody stopped it");

draw(cx);
assert!(cx.debug_bounds("scan-failed").is_some(), "it says so");
assert!(cx.debug_bounds("scan-cancelled").is_none());
assert!(cx.debug_bounds("scan-reading").is_none());
assert!(cx.debug_bounds("scan-meter").is_none(), "nothing to meter");
assert!(
cx.debug_bounds("insights-unscanned").is_some(),
"no scan is left to wait for"
);
}

/// Escape stops a widening scan and keeps the tree it started from.
#[gpui_kit::test]
fn escape_cancels_widening_and_keeps_the_tree_on_screen(
Expand Down
41 changes: 27 additions & 14 deletions crates/disktree-app/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,15 +1619,20 @@ fn worth_section(
}),
);
if app.insights.is_empty() {
let (selector, line) = if app.tree().is_some() {
("insights-none", "Nothing obviously disposable")
} else if app.scan.is_some() {
("insights-waiting", "Waiting for the scan")
} else {
// Cancelled, or failed: there is none to wait for.
("insights-unscanned", "Nothing was scanned")
};
return section.child(
div()
.debug_selector(|| selector.into())
.text_size(text::CAPTION)
.text_color(theme.secondary)
.child(if app.tree().is_some() {
"Nothing obviously disposable"
} else {
"Waiting for the scan"
}),
.child(line),
);
}
let selected = app.action_target();
Expand Down Expand Up @@ -2291,7 +2296,17 @@ fn scanning_panel(
cx: &Context<'_, Disktree>,
) -> Div {
let progress = &app.progress;
let cancelled = app.scan.is_none() && progress.cancelled;
// No scan running and no tree: it was cancelled, or it failed. Either
// way nothing is being read, so nothing here should spin.
let stopped = app.scan.is_none();
let cancelled = stopped && progress.cancelled;
let (state, title) = if cancelled {
("scan-cancelled", "Stopped reading")
} else if stopped {
("scan-failed", "Could not read")
} else {
("scan-reading", "Reading")
};
let mut panel = div()
.flex()
.flex_col()
Expand All @@ -2301,7 +2316,7 @@ fn scanning_panel(
.justify_center()
.gap(space::LG)
.bg(theme.inset)
.when(!cancelled, |panel| {
.when(!stopped, |panel| {
panel.child(
gpui_omarchy::icon(gpui_omarchy::IconName::Loader)
.size(icon::LG)
Expand All @@ -2310,14 +2325,11 @@ fn scanning_panel(
})
.child(
div()
.debug_selector(|| state.into())
.text_size(text::TITLE)
.font_weight(FontWeight::SEMIBOLD)
.text_color(theme.bright)
.child(if cancelled {
format!("Stopped reading {}", widgets::display_root(app))
} else {
format!("Reading {}", widgets::display_root(app))
}),
.child(format!("{title} {}", widgets::display_root(app))),
)
.child(
div()
Expand All @@ -2342,9 +2354,10 @@ fn scanning_panel(
cx,
)),
)
.when(!cancelled, |panel| {
.when(!stopped, |panel| {
panel.child(
div()
.debug_selector(|| "scan-meter".into())
.w(size::SCANNING_METER)
.child(widgets::meter_row(
"",
Expand All @@ -2359,7 +2372,7 @@ fn scanning_panel(
div()
.text_size(text::BODY)
.text_color(theme.secondary)
.child(if cancelled {
.child(if stopped {
"Nothing is shown from a scan that did not finish."
} else {
"Marking, zooming and the free-space meter all work as soon as it lands."
Expand Down