Repository navigation
Find metadata values the file writes with JSON escapes [patch] - #76
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
FindLocation searched the raw file text for the value a generator passes, which it got back from Deserialize<T> and is therefore unescaped. A value the file writes with an escape, such as "C:\\temp", "say \"hi\"" or the "\u03A9" System.Text.Json writes for non-ASCII, was never found, and the scoped overload fell back to the wrong entry. Each string literal is now decoded and compared with the value, and the location covers the literal's escaped contents. Quotes inside // and /* */ comments no longer open a string. The raw search stays as the fallback for text that isn't a whole string, such as a number. Fixes #68 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2bqRiw92MR91EGjva
|
This was referenced Nov 12, 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.



Fixes #68
What was wrong
MetadataFile.IndexOfTokensearched the raw file text for"<value>", then for<value>. A generator passes a value it got back fromDeserialize<T>, which is unescaped, while the file holds the escaped JSON form. SoFindLocation(@"C:\temp"),FindLocation("say \"hi\"")andFindLocation("Café")(writtenCaf\u00e9) all returnedLocation.None. When the anchor was the escaped value, the scoped overload fell back to the first unscoped match, which is the wrong entry.Change
IndexOfTokennow walks the file's string literals and decodes each one:\",\\,\/,\b,\f,\n,\r,\t, and\uXXXXin either hex case. It returns the first literal in range whose decoded value equals the needle. The location covers the literal's escaped contents between the quotes, soIndexOfTokennow also reports the match length.TryGetEnclosingObjectalready does. The scan skips//and/* */comments, whichDefaultSerializerOptionsaccepts, so a quote inside a comment no longer opens a string. The list is built once per file, on first use."\"b\"".Tests
New in
MetadataFileTests:\u00e9, and mixed-case\u03A9\u00B7m\u00b2. Each asserts the line and that the span is the escaped text.// the "old" namecomment no longer captures the search forold.With the
SourceGeneratorToolkit/change reverted, all 7 new tests fail.Full suite: 105/105 passed on Linux / .NET 10.
The local Sonar build (
.sonarlint/sonar-local.props) reports nothing in the new code. The one remaining finding in this file is S3776 on the unchangedTryGetEnclosingObject.Generated by Claude Code