dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
498 stars 254 forks source link

Duplicate diagnostics with Source Generators #996

Open papafe opened 2 years ago

papafe commented 2 years ago

I am trying to test manually if the diagnostics emitted by a source generators are correct.

To to do so I've added a reference to the source generator project with: <ProjectReference Include="..\..\SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

After rebuilding the project I get duplicate diagnostics in the error pane. For each of the diagnostic there is one with Suppression State set Active while the other is just empty. It seems that the "active" one is somehow cached, as it stays the same if I modify the text or ID of the diagnostic, for instance. If I restart Visual Studio then the cache seems to be reset, but I still have the issue of double diagnostics. The active (cached) diagnostic is also the one that is shown when hovering over the error lines in the code, and so it's quite annoying.

This happens only with the diagnostics emitted by the source generator I am working on. I am also using a launch profile for the source generator in order the test project. If I use the launch profile and I start without debugging, then only the active (cached) diagnostics are shown in the error pane.

Is there anything that I could have configured wrong?

Version Used: Microsoft.CodeAnalysis.CSharp 3.9.0 (but same behaviour with 4.3.0-2.final) Microsoft Visual Studio 17.3.0 Preview 1.0

papafe commented 2 years ago

Searching here and there a little bit more... Could this be caused by the whole source generator getting cached like in https://github.com/dotnet/roslyn/issues/48083?

sharwell commented 1 year ago

@jasonmalinowski ?