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

Source generated syntax trees should report IsGenerated #49326

Open
chsienki opened this issue Nov 12, 2020 · 9 comments
Open

Source generated syntax trees should report IsGenerated #49326

chsienki opened this issue Nov 12, 2020 · 9 comments

Comments

@chsienki
Copy link
Contributor

We should add GeneratedKind.SourceGenerator and have any syntax trees added by a generator return this value.

We should also update the original bool version of the property to report true for this value.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 12, 2020
@chsienki chsienki added the New Feature - Source Generators Source Generators label Nov 12, 2020
@mavasani
Copy link
Contributor

@chsienki Should we close out #48480?

@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 17, 2020
@jaredpar jaredpar added this to the 16.9 milestone Nov 17, 2020
@jaredpar jaredpar modified the milestones: 16.9, 16.10 Feb 9, 2021
@ericstj
Copy link
Member

ericstj commented Mar 29, 2021

Will this impact the way the compiler raises diagnostics for generated code? I can imagine there are a set of compiler checks we'd want to be ignored for generated code to simplify code-generators (eg: style analyzers) where there are others that we would want to be honored (obsolete, nullable annotations). cc @AaronRobinsonMSFT

@jmarolf
Copy link
Contributor

jmarolf commented Mar 29, 2021

Will this impact the way the compiler raises diagnostics for generated code?

Each analyzer can choose whether it needs to analyze generated code or not via the ConfigureGeneratedCodeAnalysis method.

/// <summary>
/// Configure analysis mode of generated code for this analyzer.
/// Non-configured analyzers will default to an appropriate default mode for generated code.
/// It is recommended for the analyzer to invoke this API with the required <see cref="GeneratedCodeAnalysisFlags"/> setting.
/// </summary>
public virtual void ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags analysisMode)

Today all analyzers that come with the SDK that are required for code correctness (for example security analyzers) look at generated code.

@sharwell
Copy link
Member

sharwell commented Mar 29, 2021

💭 It seems desirable to continue requiring source generators to emit the // <auto-generated/> header at the top of the file.

@eerhardt
Copy link
Member

Looking at dotnet/runtime#53275, the change is appending the .g suffix to the file to indicate this is a generated file.

How many different ways are source generators supposed to mark their files as "generated"? So far I see:

  1. emitting // <auto-generated/> header
  2. naming the file .g.cs
  3. calling ConfigureGeneratedCodeAnalysis
  4. any more?

What are the recommendations for dotnet/runtime source generators should do to mark their code as "generated"?

@AaronRobinsonMSFT
Copy link
Member

@sharwell Is the following the appropriate way to add the comment?

SyntaxFactory.Comment("<auto-generated/>").ToString()

@sharwell
Copy link
Member

sharwell commented Jun 8, 2021

@AaronRobinsonMSFT SyntaxFactory.Comment would be more for cases where you are generating a SyntaxTree. For cases where you are generating a string, rather than use ToString() like that line you could just add "// <auto-generated/>" directly.

@jinujoseph jinujoseph modified the milestones: 16.10, 17.0 Jul 16, 2021
@jaredpar jaredpar assigned chsienki and 333fred and unassigned chsienki Sep 27, 2021
@333fred 333fred modified the milestones: 17.0, 17.1 Sep 27, 2021
@333fred
Copy link
Member

333fred commented Sep 27, 2021

@chsienki can you fill out the API proposal template for this?

@chsienki
Copy link
Contributor Author

Added #56810 to track the API

@jcouv jcouv modified the milestones: 17.1, 17.2 Mar 17, 2022
@jcouv jcouv modified the milestones: 17.2, 17.3 May 14, 2022
@jaredpar jaredpar modified the milestones: 17.3, 17.4 Jun 24, 2022
@jaredpar jaredpar assigned RikkiGibson and unassigned 333fred Jun 24, 2022
@jaredpar jaredpar modified the milestones: 17.4, 17.5 Oct 7, 2022
@jaredpar jaredpar modified the milestones: 17.5, 17.6 Jan 5, 2023
@jaredpar jaredpar modified the milestones: 17.6, Backlog Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests