fix: add document character offset to element locations#415
Draft
toddr-bot wants to merge 2 commits into
Draft
Conversation
Add failing tests (marked $TODO) for the upcoming character_offset feature: - location() should return a 6-element array with offset as the 6th element - character_offset() accessor should return correct absolute positions - Offsets must account for heredoc body content - All offsets must match positions in the serialized document Addresses #101 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a 6th element to the location array returned by location(): the absolute character offset from the beginning of the document (1-indexed). - Add LOCATION_OFFSET constant to PPI::Document - Track cumulative offset in index_locations, including heredoc content - Add character_offset() accessor to PPI::Element - Update location() to return 6-element array - Remove $TODO markers from tests and update all existing location assertions to include offset values Fixes #101 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 27, 2026
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
Adds a 6th element to the location array: the absolute character offset from the beginning of the document (1-indexed). This allows tools to efficiently map between PPI elements and positions in the serialized document string, which is useful for editor integrations, source mapping, and precise text manipulation.
Fixes #101
Changes
LOCATION_OFFSETconstant toPPI::Document(index 5)_default_location,_add_location, andindex_locationsto compute and propagate the character offset, including proper accounting for heredoc body contentcharacter_offset()accessor toPPI::Elementlocation()POD to document the 6-element array formatTest plan
my $x = 1;→ each token'scharacter_offset()matches expected positionsubstr($serialized, $offset - 1, length($content))equals the token's contentGenerated by Kōan /fix
Quality Report
Changes: 5 files changed, 326 insertions(+), 224 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline