Skip to content

cargo-anvil: finish moving table adoption off the line-oriented scanner #149

Description

@Vaiz

🤖 Clawpilot here! Posted automatically by Clawpilot (an AI agent), not by a human. Please verify before acting.

Split out of #140. Re-scoped 2026-09-03: the defect originally reported here was fixed in #140 (084b42b) and is no longer part of this issue. What remains is a refactor with no known defect behind it.

What was fixed in #140

Adoption compared normalized source lines, so a hand-written workspace=true never matched a rendered workspace = true; adoption declined and the duplicate [lints] was appended. The comparison now goes through toml_edit and compares canonical path/value pairs, so spacing, entry order and quoting no longer affect the outcome. spacing_around_the_assignment_does_not_defeat_adoption pins it, and was observed failing against the pre-fix commit.

That fix also required two guards, both tested: table paths are compared as segments so ["a.b"] and [a.b] cannot collide, and the array-of-tables exclusion is applied in the rewrite as well as in candidate selection, since [bin] and [[bin]] now share a canonical path.

What remains

The comparison stage is parser-backed. The location and rewrite stages are still line-oriented, and that is what this issue now covers:

  • Table headers are still found by scanning for a line that starts with [ and ends with ]. That is why the coarse multi-line-string guard has to exist: a bracketed line inside a """ value would otherwise be read as a header. The guard declines adoption for the entire host whenever """ or ''' appears anywhere in either input — correct, but it disables the feature rather than handling the case.
  • The rewrite streams with independent in_managed and dropping booleans. Two of the defects found during review of fix(cargo-anvil): adopt an unmanaged TOML table instead of duplicating it #140 came from that pair ([[bin]] elements deleted; stale dropping surviving a managed-region boundary and removing unrelated user text, fixed in 81b85d6). The states are mutually exclusive and would be better as one enum — or absent entirely.

Proposal

Complete the move: obtain byte ranges for the approved ordinary tables from the parsed document rather than by scanning, build the non-overlapping deletion ranges up front, and produce the output by copying the gaps between them. This removes the streaming flags, and makes the multi-line-string guard unnecessary — restoring adoption for hosts that merely contain one, which today it refuses wholesale.

If parsing and source-range mapping disagree, return a conflict rather than deleting text.

Acceptance

Keep the regression coverage from #140. Add a host that contains a multi-line string and an adoptable table, which today declines and should then succeed.

Credit: raised in review of #140 by the sandersaares Copilot reviewer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions