Skip to content

Remove indentation level special-casing in TieredLinesElider#307

Merged
jas14 merged 3 commits into
mainfrom
remove-line-level-heuristic
Mar 26, 2026
Merged

Remove indentation level special-casing in TieredLinesElider#307
jas14 merged 3 commits into
mainfrom
remove-line-level-heuristic

Conversation

@jas14

@jas14 jas14 commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

As promised. Two minor changes:

First, in #all_indentation_levels, we were excluding bookends by inference: specifically, we assumed that if there were nonzero indentation levels, the lines with indentation level zero must be top-level bookends. We can just ask if &:complete_bookend? instead.

Second – and this one is more complicated – it turns out we don't need to exclude level 0 from box_groups_at_decreasing_indentation_levels_within(pane). Why?

First, note that only clean panes are ever elided. Furthermore, we can assume that there is at least one dirty pane; otherwise, we don't try to elide.

Now: for a top-level structure (no nesting), such as a multi-line string, we want to include level-0 boxes for elision. For nested structures, we don't, because we don't want to elide the bookend symbols/lines, such as {/} for a Hash [/] for an Array, etc.

However, a level-0 box for a nested structure necessarily spans the entire structure and therefore all lines; it starts with the open bookend and ends with the close bookend. And since there is at least one dirty pane, it's not possible for that level-0 box to fit within any given pane. Thus, level-0 boxes for nested structured will be filtered out of boxes_within_pane.

So, for nested structures, possible_indentation_levels will still exclude 0. For flat top-level structures, a top-level box would have been created for each top-level line, so it should still include zero.

@jas14 jas14 force-pushed the remove-line-level-heuristic branch from a14d172 to bbfdcf7 Compare March 26, 2026 21:40
@jas14 jas14 enabled auto-merge (squash) March 26, 2026 21:53
@jas14 jas14 disabled auto-merge March 26, 2026 21:57
@jas14 jas14 merged commit beda1d3 into main Mar 26, 2026
72 checks passed
@jas14 jas14 deleted the remove-line-level-heuristic branch March 26, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant