Skip to content

fix(source-edit): insert moved imports at Rust syntax boundaries - #4516

Merged
ScriptedAlchemy merged 2 commits into
fix/cold-pass-memory-retry-loopfrom
fix/move-symbol-rust-syntax-boundaries
Oct 25, 2026
Merged

ScriptedAlchemy merged 2 commits into
fix/cold-pass-memory-retry-loopfrom
fix/move-symbol-rust-syntax-boundaries

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Stack order (merge first → last): #4473 → #4478 → #4521 → #4526 → #4515 → #4510 → #4516 → #4524 → #4489 → #4488 → #4485

This PR is layer 7/11, based on #4510. Next: #4524.

Merge bottom to top using merge commits. After each parent merges, retarget its child to master before merging the child; this preserves the ancestry already integrated and avoids reintroducing conflicts.

Summary

MoveSymbol can place an inferred Rust dependency inside an existing grouped import or ahead of a module's inner attributes. This change selects a complete top-level syntax boundary with the existing Rust parser, preserving the destination's original bytes.

Closes #4420.

Changes

  • Reuse the canonical Rust parse owner and byte ranges for import placement. Keep grouped/nested imports, aliases, inner attributes/docs, BOMs and shebangs intact; preserve outer docs and attributes with their items.
  • Preserve existing destination bytes, including CRLF, trailing whitespace, whitespace-only files and files without a final newline. Appending the moved item only adds the necessary separator.
  • Return a typed source-edit-destination-syntax-unsupported error before plan capture or writes when the Rust destination is incomplete or its attachments cannot be used safely. This also applies when no dependency imports are needed.
  • Preserve generic append behavior for non-Rust destinations without inferred imports. Remove the line-based destination insertion policy while retaining the source inner-doc classifier.
  • Put the new preview/apply regressions in a separate test module so they do not conflict with fix(source-edit): preserve reexports when moving symbols #4493's re-export tests. Source re-export analysis and publication/rollback code are unchanged.

Validation

Local validation used Cargo and the repository's pinned nightly toolchain.

  • Before the fix, one existing MoveSymbol control passed and all three new journey regressions failed: the compiler rejected the grouped-import output, byte preservation failed, and a malformed destination received an accepted preview.
  • After the fix, all three journey tests pass. They cover ten valid destination shapes and four refusal cases, exercise actual dependency discovery and preview/apply, compile the generated Rust, and verify that apply publishes the exact planned bytes.
  • Complete owning source-edit library suite: 105 passed, 0 failed, 0 ignored, 0 filtered.
  • Pinned Rust formatting, git diff --check, and commitlint pass.

The full suite uses a freshly Cargo-built test binary. This executor runs as UID 0, which bypassed twelve existing reconciliation fixtures' read-only-directory failures on the initial run. Rerunning the identical binary with only the child process's DAC bypass capabilities removed passed all 105 tests; no assertions or repository settings were changed for that rerun.

@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1ac94df

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) October 24, 2026 14:59
@ScriptedAlchemy
ScriptedAlchemy force-pushed the fix/move-symbol-rust-syntax-boundaries branch from f65dd3f to a833f1a Compare October 24, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(source-edit): insert MoveSymbol imports at syntax boundaries, not inside grouped imports or before inner attributes

1 participant