zed-industries/zed · error

compute_indents_fn is required for UniformListDecoration

Error message

compute_indents_fn is required for UniformListDecoration

What it means

ui's UniformListDecoration draws indent guides over a GPUI uniform list by computing visible entries' indents through a caller-supplied closure (compute_indents_fn). The paint path requires that closure and panics on first paint without it (crates/ui/src/components/indent_guides.rs:229). The builder method with_compute_indents_fn (crates/ui/src/components/indent_guides.rs:84) exists precisely to install it.

Source

Thrown at crates/ui/src/components/indent_guides.rs:229

        fn compute(
            &self,
            mut visible_range: Range<usize>,
            bounds: Bounds<Pixels>,
            _scroll_offset: Point<Pixels>,
            item_height: Pixels,
            item_count: usize,
            window: &mut Window,
            cx: &mut App,
        ) -> AnyElement {
            let includes_trailing_indent = visible_range.end < item_count;
            // Check if we have entries after the visible range,
            // if so extend the visible range so we can fetch a trailing indent,
            // which is needed to compute indent guides correctly.
            if includes_trailing_indent {
                visible_range.end += 1;
            }
            let Some(ref compute_indents_fn) = self.compute_indents_fn else {
                panic!("compute_indents_fn is required for UniformListDecoration");
            };
            let visible_entries = &compute_indents_fn(visible_range.clone(), window, cx);
            let indent_guides = compute_indent_guides(
                visible_entries,
                visible_range.start,
                includes_trailing_indent,
            );
            self.render_from_layout(indent_guides, bounds, item_height, window, cx)
        }
    }
}

/// Implements the necessary functionality for rendering indent guides inside a sticky items.
mod sticky_items {
    use crate::StickyItemsDecoration;

    use super::*;

View on GitHub (pinned to f4178619ac)

Solutions

  1. Call .with_compute_indents_fn(entity, closure) on the decoration before it renders; the closure receives the visible Range<usize> plus window/cx and returns the indents for those entries.
  2. If you cannot supply indents, use the non-uniform decoration variant or skip the decoration entirely.
  3. Harden the API: require the closure at construction (or debug_assert in the builder) so misuse fails at build time, not paint time.

Example fix

// before
let decoration = IndentGuides::uniform_list_decoration(); // no compute fn

// after
decoration.with_compute_indents_fn(entity, |this, visible_range: Range<usize>, _window, _cx| {
    this.visible_indents(visible_range)
})
Defensive patterns

Strategy: validation

Validate before calling

// install the required closure before the element can paint
let decoration = decoration.with_compute_indents_fn(entity, |this, range: Range<usize>, _window, _cx| {
    this.indents_for_range(range)
});

Prevention

When it happens

Trigger: Constructing a UniformListDecoration (indent guides for a uniform-list component such as a tree or outline) without calling .with_compute_indents_fn(view_entity, closure), then letting the element render.

Common situations: Adding indent guides to a new uniform-list surface from an example that omits the closure; refactors dropping the builder call; using the uniform-list decoration where the plain element-iterator variant was intended.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/af63da4eb7bc2f8b. Report an issue: GitHub.