dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.91k stars 4.01k forks source link

Source Generators: Diagnostic issues with locations in Additional Files files do not appear in VS's error list #49531

Open AArnott opened 3 years ago

AArnott commented 3 years ago

Version Used: VS 16.9 Preview 2 (30718.196.main)

I have a Source Generator myself that needs to show diagnostics within Additional Files. It works in the command line build, and running a build from within VS does get the diagnostic to appear in the error list, but the background compiler doesn't ever add or remove the diagnostic from the error list, so it doesn't show up until a full build, and it doesn't disappear after being resolved without another full build.

My actual repro with the line that calls ReportDiagnostic: https://github.com/dotnet/pinvoke/blob/bf31a9e6b13ea7a5f0c436705b338e8530b814dd/src/Win32.CodeGen/SourceGenerator.cs#L66

AArnott commented 3 years ago

@chsienki @jasonmalinowski can you please take a look?

Code-Grump commented 1 month ago

The behaviour seems to have changed since this was raised: errors now appear in the Errors window, but list the project file as the source, not the additional file: image

CyrusNajmabadi commented 1 month ago

Was that an error produced by an explicit build command? Or during live analysis? Thanks!

Code-Grump commented 1 month ago

That error can be produced during live analysis.

During an explicit build, the output is the correct additional source file, as reported in the Diagnostic object passed to ReportDiagnostic:

image

CyrusNajmabadi commented 1 month ago

Can you link us to a repro? Thanks @Code-Grump

Code-Grump commented 1 month ago

https://github.com/Code-Grump/additional-sources-diagnostics-repro This sample produces a diagnostic for every text file added.

image