Fix source generator diagnostic locations for incremental caching #1153
+67
−22
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.
DiagnosticInfostored RoslynLocationobjects but excluded them from equality comparisons. When the incremental generator cache returned cached values, stale locations from earlier compilations were reused, causing Roslyn to throw exceptions.Changes
LocationInforecord struct — Stores serializable location data (file path, text span, line span) instead of RoslynLocationobjectsDiagnosticInfoto record struct — UsesLocationInfo?instead ofLocation?; record equality automatically includes all fieldsLocationInfo.ToLocation()creates freshLocationwhen building diagnosticsWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
http://crl3.digicert.com:443/DigiCertCSRSA4096RootG5.crl/usr/share/dotnet/dotnet dotnet restore(http block)http://crl3.digicert.com:443/DigiCertTrustedG4RSA4096SHA256TimeStampingCA.crl/usr/share/dotnet/dotnet dotnet restore(http block)http://crl3.digicert.com:443/NETFoundationProjectsCodeSigningCA2.crl/usr/share/dotnet/dotnet dotnet restore(http block)http://crl3.digicert.com:443/sha2-assured-cs-g1.crl/usr/share/dotnet/dotnet dotnet restore(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Source Generator returns diagnostics with locations outside the current compilation</issue_title>
<issue_description>Originally reported by @AArnott at dotnet/vscode-csharp#8887
Describe the bug
Roslyn is throwing an exception which is being caused by the diagnostics returned from the MCP source generator. The locations being returned for the diagnostics are not from the current Compilation. This is likely caused by not including the location in the equality check leading to returning locations from earlier iterations. See
csharp-sdk/src/ModelContextProtocol.Analyzers/XmlToDescriptionGenerator.cs
Line 533 in 774411b
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It works.
Logs
The fix fails with the error given above.
C# output window pane