fix_plan: structured edit previews on diagnostics (Zero-style, ILO-48 MVP)#621
Merged
Conversation
Add FixPlan { path, edits: Vec<FixEdit> } and FixEdit { line_start,
line_end, before, after } matching the Zero PR #137 schema. Wire
fix_plan serialization into --json output. No diagnostics emit plans yet.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add Diagnostic::derive_fix_plan() which pattern-matches on code and builds a structured FixPlan from the primary span + source text: - ILO-T004 / ILO-T003: parse "did you mean 'X'?" from hint, replace span - ILO-T032: bare fmt/fmt2 → prepend "prnt " before the call - ILO-L002: underscore ident → hyphenated form from suggestion backticks Wire enrich() closure in check_cmd to call derive_fix_plan() after attaching source and diag_path (file-only; absent for inline code). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Unit tests in diagnostic::tests::derive_fix_plan_* cover: - T004 typo rename, T003 type rename, T032 fmt prefix, L002 hyphen - absent-without-hint and absent-without-source guard cases - JSON shape (line_range array, before/after keys, path field) Integration tests in json_output_contracts exercise the full check --json → NDJSON stderr pipeline for each wired diagnostic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JSON_OUTPUT.md: expand ilo check section with diagnostic NDJSON shape, optional fix_plan schema (Zero PR#137 style), and table of codes that emit structured edits. ai.txt: add [fix_plan] note in ERROR DIAGNOSTICS section describing the field and which codes populate it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Extends derive_fix_plan() with three new code handlers:
- ILO-T008 (return type mismatch): wraps the offending return expression
with `str`/`num` when the hint identifies a cast; no-ops for non-cast types
- ILO-P011 (reserved keyword as identifier): renames the span token to
`<name>2` (safe mechanical rename with no semantic ambiguity)
- ILO-T041 (nil-coalesce on Result): rewrites `expr ?? default` to
`?expr{~v:v;^_:default}` by splitting on the ` ?? ` operator
Adds 5 unit tests in src/diagnostic/mod.rs and 4 integration tests in
tests/json_output_contracts.rs exercising the live binary via ilo check --json.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 22, 2026
e81e8df to
4cdd861
Compare
4 tasks
fix-plans: wire more codes (T008, P011, T041)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FixPlan { path, edits: Vec<FixEdit { line_start, line_end, before, after } }to theDiagnosticstruct, matching the Zero PR build: collapse internal whitespace in compact spec #137 schemafix_planis serialized as an optional field in--jsonNDJSON output (absent when no mechanical fix is known)Diagnostic::derive_fix_plan()computes the plan from code + span + source — called incheck_cmdvia anenrich()closure"did you mean 'X'?"hint → rename span to Xfmt/fmt2result discarded → prependprntbefore the callpathis populated from the file path when checking a file; absent for inline codeJSON_OUTPUT.mdupdated with full diagnostic shape and fix_plan tableai.txtERROR DIAGNOSTICSsection updated with[fix_plan]noteTest plan
cargo test --lib diagnostic::tests::derive_fix_plan— 7 unit tests covering all four derivation paths, guard cases, JSON shape, path fieldcargo test --test json_output_contracts check_json— 4 integration tests running the fullilo check --jsonpipelinecargo test --lib— 3338 lib tests, 0 failurescargo test --test json_output_contracts— 15 tests, 0 failuresDeferred follow-ups (not in this PR)
ilo applysubcommand to consume a fix_plan JSON and rewrite the file🤖 Generated with Claude Code