You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scoped FindLocation("Foot", "Meter") lands inside "SquareMeter" again when the exact "Meter" is before the anchor or in an earlier entry (#33 returns via #67's range split) #80
the whole "Meter" at offset 10 (the documented fallback, "the first unscoped match")
When this happens, the diagnostic squiggle goes under the wrong name. In the second row it lands in the same entry. In the third row it lands in a different, correctly spelled entry. This is the symptom #33 fixed.
Why
IndexOfToken(value, start, end) (SourceGeneratorToolkit/MetadataFile.cs ≈ line 266) prefers an exact quoted match over a plain substring match, but only within the one range it is given. Since #67 (the fix for #66), FindLocation(anchor, needle) (≈ line 134) calls it on four ranges in turn:
after the anchor, inside its object
before the anchor, inside its object
forward from the anchor
the whole file, via FindLocation(needle)
Each call returns its range's substring hit as soon as that range has no exact hit. So a substring match in an earlier range beats an exact match in a later one:
Row 2: range 1 has no exact "Meter", so its substring match inside SquareMeter wins over the exact "Meter" in range 2.
Row 3: range 3 takes the substring match in the later entry, so the exact match that range 4 would find is never reached.
The two existing fixes each hold on their own, but the combination is untested. Open PR #76 (for #68) keeps the same per-range exact-then-substring shape, so it doesn't change this.
Suggested fix
Split IndexOfToken into an exact-only search and a substring-only search. In FindLocation(anchor, needle):
Run the exact-only search over all four ranges, in the current order.
Fall back to the substring search over the same ranges only when none of them has an exact match.
Acceptance criteria
A test for each failing row above: FindLocation("Foot", "Meter") on that JSON points at offset 9 for row 2 and offset 10 for row 3.
Recommended next step: the issue's suggested fix. Run the exact-only search across all four ranges first, and fall back to the substring search only if none of them has an exact match. Add the two failing rows as tests.
Activity
matt-edmondson commentedon Nov 12, 2026
Triage
SourceGeneratorToolkit/MetadataFile.cs, inFindLocation(anchor, needle)andIndexOfToken.MetadataFile.FindLocation(anchor, needle)points the diagnostic at the wrong entry when the needle's key comes before the anchor's key in the same JSON object #66 (closed): the two fixes that combine to cause this. Their tests must keep passing.//and/* */comments, and a"in a comment sends a scoped lookup to the wrong entry #78: comment handling in the same lookup.C:\temp,say "hi", and System.Text.Json-written non-ASCII names likeΩ·m²can't be located #68) rewrites the sameIndexOfTokencode to handle escapes but keeps the per-range exact-then-substring order, so it does not fix this. Land Find metadata values the file writes with JSON escapes [patch] #76 first, then split the search into exact and substring passes on top of it, to avoid conflicts.Generated by Claude Code