Skip to content

feat: let a walk see every block that holds one - #38

Merged
webern merged 2 commits into
mainfrom
m/walk-ancestors
Sep 26, 2026
Merged

webern merged 2 commits into
mainfrom
m/walk-ancestors

Conversation

@webern

@webern webern commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Human Summary

A refactor of the parsed tree representation.

Summary

Document::walk used to yield each block with its parent. It now yields each block with every block that holds it, outermost first. The parent is the last of them, and the depth is how many there are. The walk already kept those blocks on its stack and threw them away; now each block gets a copy.

Of the three options in #29, this is the first: a Vec<&Block> per block.

  • One walk. A second walk next to the old one would make walk() redundant, since its parent is just ancestors.last().
  • A closure taking (&Block, &[&Block]) cannot return early or use iterator adaptors. repo_layout returns from inside its walk, and the tests use find, filter and map.
  • The cost is a copy of a few pointers per nested block. A top-level block gets an empty Vec, which does not allocate.

The signature of walk() changed

The item type went from (&Block, Option<&Block>) to (&Block, Vec<&Block>).

  • A caller that writes for (block, _) in document.walk() compiles unchanged.
  • A caller that uses the parent now writes ancestors.last() instead of parent.

If the banned_phrases lint (#32) uses the parent, whichever of the two PRs merges second needs that one-line change.

Callers

  • density uses the whole chain. See the bug below.
  • The tree helper in tests/document.rs rebuilt each block's depth by searching for its parent by pointer. It is now ancestors.len().
  • The corpus test checks each block against ancestors.last().
  • max_emphasis, repo_layout and banned_chars ignore the second element and are untouched.

docs/design/deslag.asbuilt.md now describes the walk. To make room I cut detail from the same section (the metadata-block note, the examples of spans, "soft and hard", "never split"). The doc is 16,237 bytes, 10 fewer than on main.

Bug fixed: density and paragraphs nested in a list item

The density lint says a paragraph inside a list item is held to max_item_chars, and documents Kind::Paragraph as "a paragraph outside any list item". The code only checked the paragraph's direct parent. So a paragraph in a block quote inside a list item was held to max_paragraph_chars and reported as a paragraph. It now checks every block that holds it.

This is the one intended change in output:

  • No tests/cases/**/*.stderr file changes.
  • I ran deslag check with [md.lints.density] over copies of tests/corpus/{human,llm,mixed}, before and after. The reports of three mixed/ fixtures change. For example, a quoted abstract inside a list item in dckc--awesome-ocap/README.md is now reported as a list item.
  • No fixture passes or fails that did not before. The failing files stay at 53 human/, 92 llm/ and 126 mixed/.

The regression test is a_paragraph_in_a_quote_in_a_list_item_is_held_to_the_item_s_limit in tests/density.rs. It is its own commit.

Testing

  • make ci: exit 0
  • New test a_walk_gives_every_block_that_holds_a_block_outermost_first in tests/document.rs: a list inside a block quote inside a list item, asserting the kinds of each block's chain
  • The density regression test fails against main's src/ and passes here
  • The corpus density run above, before and after

References

Document::walk now yields each block with every block that holds it,
outermost first, instead of its parent alone. The parent is the last of
them, and the depth is how many there are. The walk already kept these
blocks on its stack; it now hands each block a copy of them.

A lint that needs to know where a block sits, such as how deeply a list
is nested, no longer has to rebuild the tree from parents.
The density lint held a paragraph to max_item_chars only when a list
item was its parent. A paragraph in a block quote inside a list item
was held to max_paragraph_chars instead, though the lint's docs say a
paragraph inside a list item counts as an item. It now looks at every
block that holds the paragraph.

In the corpus this changes the reports of three mixed/ fixtures. No
fixture passes or fails that did not before.
@webern webern added bug Something isn't working enhancement New feature or request area/parse Deals with parsing the files we are linting. area/lint Deals with the linting algorithms themselves, how they work. labels Sep 26, 2026
@webern webern mentioned this pull request Sep 26, 2026
9 tasks done
@webern webern added the ai Primarily authored by AI (whether PR, Issue, Whatever) label Sep 26, 2026
@webern
webern merged commit 93c3b68 into main Sep 26, 2026
2 checks passed
@webern
webern deleted the m/walk-ancestors branch September 26, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) area/lint Deals with the linting algorithms themselves, how they work. area/parse Deals with parsing the files we are linting. bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let a walk see every block that holds a block

1 participant