Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceGenerator diagnostics not appearing in error list #49664

Closed
YairHalberstadt opened this issue Nov 30, 2020 · 5 comments · Fixed by #60474
Closed

SourceGenerator diagnostics not appearing in error list #49664

YairHalberstadt opened this issue Nov 30, 2020 · 5 comments · Fixed by #60474
Assignees
Milestone

Comments

@YairHalberstadt
Copy link
Contributor

YairHalberstadt commented Nov 30, 2020

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> {}
  1. Build, producing this diagnostic:
error SI0102: Error while resolving dependencies for 'int': We have no source for instance of type 'int'
  1. Navigate to the location of the error.
  2. The diagnostic does not show up in diagnostics tab when set to show "Intellisense only" diagnostics. Neither do red squigglies appear.
  3. 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.
  4. You can navigate to the generated code, e.g. by clicking goto definition of _disposed in public class Container : IContainer<int> { int x => _disposed; }
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 30, 2020
@jasonmalinowski jasonmalinowski removed the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 1, 2020
@jasonmalinowski jasonmalinowski self-assigned this Dec 1, 2020
@jinujoseph jinujoseph added the Bug label Dec 11, 2020
@jinujoseph jinujoseph added this to the Backlog milestone Dec 11, 2020
@jasonmalinowski jasonmalinowski modified the milestones: Backlog, 16.9 Jan 23, 2021
@ReubenBond
Copy link
Member

ReubenBond commented Jan 23, 2021

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
Copy link

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.

@DamianEdwards
Copy link
Member

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
Copy link

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

@jasonmalinowski jasonmalinowski modified the milestones: 17.2, 17.3 Apr 8, 2022
jasonmalinowski added a commit to jasonmalinowski/roslyn that referenced this issue Apr 20, 2022
This adds support for showing generator-produced diagnostics in the
error list. The implementation generally follows how we handle
diagnostics for files that we were unable to read in the IDE -- there is
a placeholder analyzer that represents the diagnostics in our various
state sets.

The one interesting thing this changes a bit is our handling of the
full-solution analysis flag. While testing this (and seeing how the file
load diagnostics worked), I noticed that we had an early bail in
"analyze project" that meant two things:

Unless you had FSA on, there was no way to actually view file load
diagnostics; this seemed odd since you then might have diagnostics in
your error list about missing types, but you wouldn't see the root
problem.  If you turned FSA back off, nothing would ever run to make the
FSA-produced diagnostics go away, short of you manually opening files or
something.  Thus I am changing the FSA handling a bit: if FSA is off,
rather than skip everything we are only skipping the analysis now; this
ensures that we are clearing out old/stale diagnostics, and we have an
opportunity to still show the generator and file load diagnostics that
we may have on hand. We only still produce those for other files (or
things in the dependency graph) for files that are open though -- the
key here is unlike regular diagnostics, these are diagnostics we know
that came from the very production of the compilation itself. If the
file is open, we're already going to have compilations being created for
it (indeed, at least for open file diagnostics!), so we're not creating
any extra work than we already had.

Fixes dotnet#49664
Fixes dotnet#58435
Fixes dotnet#54098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants