24 add insert at operation for inserting into a list at a specific index#28
Merged
nathanjmcdougall merged 8 commits intoMay 19, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new “insert at index” capability for YAML block sequences, exposed through the Python Document/Editor APIs and implemented in the Rust patch-application pipeline to preserve round-tripping behavior (especially comments/formatting).
Changes:
- Add
Document.insert(..., index, value)andEditor.insert(..., index, value)with Pythonlist.insert()-style index semantics (negative indices, clamping). - Introduce a new core operation
Op.insert_atimplemented as a local (non-yamlpatch) op and routed throughapply_patches_impl. - Add test coverage across core ops, document/editor APIs, and an integration scenario (pre-commit repo insertion).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_integration.py | Adds an end-to-end test for inserting a repo into a pre-commit config list. |
| tests/test_editor.py | Adds editor-level tests for insert() behavior and persistence to disk. |
| tests/test_document.py | Adds document-level tests for insert() semantics and error cases. |
| tests/test_core_ops.py | Adds core operation constructor + apply_patches tests for insert_at. |
| src/yamltrip/editor.py | Adds Editor.insert() wrapper around Document.insert(). |
| src/yamltrip/document.py | Adds immutable Document.insert() API that emits an Op.insert_at patch. |
| src/yamltrip/_core.pyi | Updates native-module type stubs with Op.insert_at. |
| src/ops.rs | Adds LocalOp / OpInner to support local-only ops and implements Op.insert_at. |
| src/document.rs | Routes local ops in apply_patches_impl and implements apply_insert_at string surgery. |
| doc/specs/2026-05-19-insert-operation-design.md | Design spec documenting the API, routing approach, and algorithm. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.