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.92k stars 4.01k forks source link

SourceGenerator diagnostics not appearing in error list #49664

Closed YairHalberstadt closed 2 years ago

YairHalberstadt commented 3 years ago

Version Used: visual studio 16.8.2 and 16.9 preview 1

Intellisense shows members created by the source generator, and you can navigate to the generated code. Building displays the diagnostics. However the diagnostics don't appear in the diagnostics tab when set to show "Intellisense only" diagnostics.

Steps to Reproduce:

  1. Create a new project referencing StrongInject

  2. Add a file:

    using StrongInject;
    public class Container : IContainer<int> {}
  3. Build, producing this diagnostic:

    error SI0102: Error while resolving dependencies for 'int': We have no source for instance of type 'int'
  4. Navigate to the location of the error.

  5. The diagnostic does not show up in diagnostics tab when set to show "Intellisense only" diagnostics. Neither do red squigglies appear.

  6. Intellisense shows the generated members, e.g. when typing (| marks location of caret) public class Container : IContainer<int> { int x => _| } it will display _disposed in the completion list.

  7. You can navigate to the generated code, e.g. by clicking goto definition of _disposed in public class Container : IContainer<int> { int x => _disposed; }

ReubenBond commented 3 years ago

I am also experiencing this issue while trying to create a Source Generator. The highlighted line in this source window corresponds to one of the errors listed below. image image

My branch is here, if that helps: https://github.com/ReubenBond/orleans/tree/feature/source-generator, and the source generator is here: https://github.com/ReubenBond/orleans/blob/feature/source-generator/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs

lukblazewicz commented 2 years ago

Just to confirm and bump up - we experience this issue a lot (VS 2022) when trying to build a Blazor project after indirectly introducing some errors in razor files. By indirectly, I mean making some refactorings inside the model/service layer that are not properly reflected in the razor files (while the erroneous Blazor components remain closed in the editor).

It causes false positives scenario - the error list is empty while the build is failing for no obvious reason. The only fallback solution is to try building the project from CLI and look for the actual errors throughout the console output.

Significantly affects the quality of life, to be honest.

NTaylorMullen commented 2 years ago

More related issues:

DamianEdwards commented 2 years ago

Just adding my own voice here as this is impacting warnings in Razor files (.cshtml and .razor) since the Razor compiler switched to using a source generator in .NET 6. Nullable warnings in Razor files do not show up in the VS Error List unless the file is open in the editor. I often don't see the warning until the CI build fails 😢

Siphonophora commented 2 years ago

Agreed this is a pretty big quality of life issue for razor files. Not being able to trust the error list is disconcerting.