Skip to content

Emit diagnostics for unsupported RDG scenarios #49417

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

Merged
merged 2 commits into from
Jul 17, 2023
Merged

Conversation

captainsafia
Copy link
Member

@ghost ghost added the area-runtime label Jul 14, 2023
@captainsafia captainsafia added feature-rdg area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jul 14, 2023
@captainsafia captainsafia marked this pull request as ready for review July 14, 2023 21:27
@captainsafia captainsafia requested review from mitchdenny and eerhardt and removed request for halter73, Tratcher, BrennanConroy and mitchdenny July 14, 2023 21:27
{
diagnostics.Add(Diagnostic.Create(DiagnosticDescriptors.TypeParametersNotSupported, location));
}
if (response.ResponseType?.DeclaredAccessibility is Accessibility.Private or Accessibility.Protected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (response.ResponseType?.DeclaredAccessibility is Accessibility.Private or Accessibility.Protected)
if (response.ResponseType?.DeclaredAccessibility is Accessibility.Private or Accessibility.Protected)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless these are meant to be else if

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless these are meant to be else if

I debated this but I've always like the upfront disclosure you get when all the warnings are emitted at once instead of the progressive disclosure that allows you to keep fixing things until you get it right.

Copy link
Member

@ReubenBond ReubenBond Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SemanticModel has an IsAccessible(Location, ISymbol) method. I believe that is the intended way to check for accessibility instead of DeclaredAccessibility In the past, I've used it like this: semanticModel.IsAccessible(0, symbol).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you used this in a generator? It seems like the API works by assessing accessibility within the context of an existing syntax tree, but here we're trying to check accessibility in code we haven't generated yet.

var parameter = new EndpointParameter(this, method.Parameters[i], wellKnownTypes);
var parameterSymbol = method.Parameters[i];
parameterSymbol.EmitRequiredDiagnostics(Diagnostics, Operation.Syntax.GetLocation());
if (Diagnostics.Count > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fragile? What if we emit info diagnostics, or diagnostics from a different part of the generator unrelated to this endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we emit info diagnostics, or diagnostics from a different part of the generator unrelated to this endpoint?

At the moment, we're strictly using diagnostics as a way to indicate that some aspect of the endpoint is wrong and we can't statically generate it.

If we do decide to start emitting info-level diagnostics (I dunno how meaningful that would be for a source generator given that it's only visible in builds triggered from the IDE), we'd have to consider other aspects of the implementation, such as the way we use the lack of diagnostics to determine if we haven't been able to generate an endpoint.

All in all, I feel safe with the simplicity of .Count > 0 here given the constraints were operating under compared to a more thorough check.

@captainsafia captainsafia merged commit 1b16209 into main Jul 17, 2023
@captainsafia captainsafia deleted the safia/rdg-bug-fixes branch July 17, 2023 21:50
@ghost ghost added this to the 8.0-preview7 milestone Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdg
Projects
None yet
4 participants