What's wrong
MetadataFile.Deserialize<T> (SourceGeneratorToolkit/MetadataFile.cs, the local ParseFailed function) reports the parse failure with context.Report(parseFailed, FileName, ex.Message). DiagnosticCatalog.Report always reports at Location.None (DiagnosticCatalog.cs:103).
For a JsonException, the exception already carries LineNumber and BytePositionInLine. MetadataFile also already has the text and a LocationAt(index, length) helper, which it uses to make its other diagnostics navigable. The toolkit's most common diagnostic is the one that isn't navigable, even though the README advertises navigable diagnostics.
Failure scenario
A things.json containing {"things": [1,,2]} on line 3 produces a MetadataParseFailed diagnostic with no file or line in the IDE error list. The only pointer is the "LineNumber: 2 | BytePositionInLine: …" text buried in the message, and double-clicking goes nowhere.
Suggested fix / acceptance criteria
- In the
JsonException branch, when ex.LineNumber has a value and the text is available, compute an offset from ex.LineNumber and ex.BytePositionInLine and report with ReportAt at that location.
BytePositionInLine counts UTF-8 bytes, so convert it to a character offset on non-ASCII lines.
- Clamp the offset to the line length.
- Keep
Location.None for the NotSupportedException, InvalidOperationException and null-document cases, and for a JsonException without a line number.
- Test: malformed JSON on line 3 produces a diagnostic whose
Location.GetLineSpan() has the metadata file's path and StartLinePosition.Line == 2.
What's wrong
MetadataFile.Deserialize<T>(SourceGeneratorToolkit/MetadataFile.cs, the localParseFailedfunction) reports the parse failure withcontext.Report(parseFailed, FileName, ex.Message).DiagnosticCatalog.Reportalways reports atLocation.None(DiagnosticCatalog.cs:103).For a
JsonException, the exception already carriesLineNumberandBytePositionInLine.MetadataFilealso already has the text and aLocationAt(index, length)helper, which it uses to make its other diagnostics navigable. The toolkit's most common diagnostic is the one that isn't navigable, even though the README advertises navigable diagnostics.Failure scenario
A
things.jsoncontaining{"things": [1,,2]}on line 3 produces a MetadataParseFailed diagnostic with no file or line in the IDE error list. The only pointer is the "LineNumber: 2 | BytePositionInLine: …" text buried in the message, and double-clicking goes nowhere.Suggested fix / acceptance criteria
JsonExceptionbranch, whenex.LineNumberhas a value and the text is available, compute an offset fromex.LineNumberandex.BytePositionInLineand report withReportAtat that location.BytePositionInLinecounts UTF-8 bytes, so convert it to a character offset on non-ASCII lines.Location.Nonefor theNotSupportedException,InvalidOperationExceptionand null-document cases, and for aJsonExceptionwithout a line number.Location.GetLineSpan()has the metadata file's path andStartLinePosition.Line == 2.