Repository navigation
Point scoped FindLocation at the anchor's own entry when the needle is written first [patch] - #67
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
…s written first [patch] FindLocation(anchor, needle) only searched forward from the anchor, so a needle written before the anchor in the same JSON object was found in a later entry, or fell back to an earlier one. Search the anchor's enclosing object first, after then before the anchor, skipping strings and nested objects, before the forward and unscoped fallbacks. Fixes #66 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3tezLDV1yfkEQRQji
|
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.



Fixes #66
What changed
MetadataFile.FindLocation(anchor, needle)only searched forward from the anchor. JSON objects have no key order, so when the needle's key came before the anchor's key in the same entry ({"base":"Meter","name":"Foot"}), the search found the needle in a later entry, or fell back to the first unscoped match in an earlier one.The search now runs in this order:
The enclosing object is found with a forward scan from the start of the file. That scan tracks string state and nesting, so braces inside strings and nested objects written before the anchor are not mistaken for the entry's braces.
IndexOfTokengains an end-bounded overload for this.Tests
Foot/Yardexample returns line 1. TheInch/Footvariant returns theFootentry instead of falling back toInch. A third case puts{/}inside a string and a nested object before the anchor.Generated by Claude Code