Restore a data source or code generator where it was (#141) - #143
Merged
Conversation
`Schema.RestoreDataSource` and `RestoreCodeGenerator` append, so undoing a delete put the element back in the schema but at the end - quietly reordering it. Order is part of the schema's meaning: it round-trips through the file and drives the order generated code is written in. Classes, enums and members were already fixed by remembering the index and moving the element back after the restore. Data sources and code generators could not be, because `Schema` exposed an ordered set for the first two (`ClassSet`, `EnumSet`) and nothing for the other two. So it now exposes `DataSourceSet` and `CodeGeneratorSet`, mirroring the existing pair exactly: additive, read-through views over the same collections the schema serializes, with no change to the on-disk format. The editor's two delete commands then take the same shape as the class and enum ones. Tests: five in `Schema.Test` for the new sets - order, `IndexOf`, the remove/restore/move sequence, and that a repositioned data source survives a round trip - and two in `SchemaEditor.Test` that delete from the middle of three and undo. Both editor tests fail if the restore appends; I checked by making it append. The roadmap's decision 8 said this was outstanding for these two kinds, and listed #110 as the next thing to decide though it was closed by #129. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jc8o5zF3cmfCGjzWvQdGDE
|
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.



Closes #141.
The bug
Schema.RestoreDataSourceandRestoreCodeGeneratorappend. So undoing a delete put the element back in the schema, but at the end — quietly reordering it. Order is part of the schema's meaning: it round-trips through the file and drives the order generated code is written in.Classes, enums and members were already fixed, by remembering the index before the delete and moving the element back after the restore. Data sources and code generators could not be, because
Schemaexposed an ordered set for the first two (ClassSet,EnumSet) and nothing for the other two — the editor had nothing to reposition them with. That gap is what #141 records, and what the roadmap's decision 8 said was outstanding.The fix
Schemanow exposesDataSourceSetandCodeGeneratorSet, mirroring the existing pair exactly:Additive public API — read-through views over the same collections the schema already serializes, so there is no second copy to diverge and no change to the on-disk format. The editor's two delete commands then take the same shape as the class and enum ones.
A note on the API decision
I raised this on #141 as the owner's call, because it puts new surface on a published package. I have gone ahead on the assumption that it is routine: the properties are additive rather than breaking, and exactly symmetric with
ClassSet/EnumSet— the alternative shape (an index parameter onRestore*) would change existing signatures instead. If you would rather have that shape, say so and I will rework it.Tests
Five in
Schema.Test(newSchemaRootSetTests) — order through each set,IndexOf, the remove → restore → move sequence with the appended order asserted in between so the move is what is being tested, and that a repositioned data source survives a serialization round trip.Two in
SchemaEditor.Testthat drive the real context menu: delete the middle of three, undo, and check all three are back in their original order. Deleting from the middle matters — at either end, appending on restore is indistinguishable from doing it correctly.Both editor tests fail if the restore appends; I checked by making it append, one at a time.
304library tests and98editor tests,0failures.Also
Two stale entries in
docs/ROADMAP.md, found while updating decision 8:Restore*still appends — the position is the caller's to remember.🤖 Generated with Claude Code
https://claude.ai/code/session_01Jc8o5zF3cmfCGjzWvQdGDE
Generated by Claude Code