Skip to content

Remove stale generated files when an element is renamed or deleted - #314

Merged
matt-edmondson merged 4 commits into
mainfrom
claude/project-thread-kk9on7-288
Oct 22, 2026
Merged

matt-edmondson merged 4 commits into
mainfrom
claude/project-thread-kk9on7-288

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Requested by Matt · project thread

Before: when you renamed or deleted a class, enum, interface or semantic type and generated again, the old file (for example Item.g.cs or Packet.gen.hpp) stayed in the output directory. It kept compiling a type the schema no longer declares.

After: GenerateToDisk removes the files it wrote last time and no longer produces, and its message says how many it removed. A file it never wrote is left alone. That covers hand-written files and the output of other generators sharing the directory. SchemaGenerationResult.RemovedFiles lists what was removed.

How: each generator writes a small manifest, .<generator name>.schema-generated, in its output directory, listing the files it wrote. The next run deletes manifest entries that are missing from the new output before it writes anything, so a rename that only changes case still leaves the new file on a case-insensitive file system. An entry that is rooted, or that resolves outside the output directory, is ignored. A file that cannot be deleted is reported in the message and kept in the manifest so the next run retries it. The first run after upgrading has no manifest, so it removes nothing. Renaming a generator starts it with an empty record, for the same reason.

Tests cover a rename, a deletion, a case-only rename, an untouched hand-written file, and manifest entries that escape the directory. A C++ test covers the rename too. Without the delete, the rename and deletion tests fail.

Closes #288


Generated by Claude Code

GenerateToDisk now records the files each code generator wrote in a
per-generator manifest in the output directory, and on the next run
deletes the recorded files it no longer produces. Files it never wrote,
including hand-written ones and other generators' output, are untouched.

Closes #288

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017diBTKdccitjf28kU2Syfq
@matt-edmondson matt-edmondson self-assigned this Oct 20, 2026
Comment thread Schema/Generation/GeneratedFileManifest.cs Fixed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YNKVuFTzTt8TiFb94MS4eW
Main now checks every destination stays inside the output directory and reports a write it cannot
make as WriteFailed. Both checks run before stale files are removed, and creating the output
directory and writing the manifest report a failure the same way rather than throwing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9FBXHS37WoAF87LDY2ZVV
The unknown-option check refused every option on validate, so
`validate --no-data` failed once both changes reached main.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017diBTKdccitjf28kU2Syfq
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 9d7e2be into main Oct 22, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the claude/project-thread-kk9on7-288 branch October 22, 2026 13:19
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.

Generating again never removes files from an earlier run, so a deleted or renamed class/enum/type keeps compiling from the output directory

2 participants