-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New generator apis #74127
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
New generator apis #74127
Changes from all commits
77f382e
96cdcc7
26800b6
b675fbb
fd12ffa
a316de1
28299c6
b97efcc
924eeb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Microsoft.CodeAnalysis.Compilation! compilation) -> Microsoft.CodeAnalysis.GeneratorDriver! | ||
| Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Microsoft.CodeAnalysis.Compilation! compilation, System.Func<Microsoft.CodeAnalysis.GeneratorFilterContext, bool>? generatorFilter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.GeneratorDriver! | ||
| Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Microsoft.CodeAnalysis.Compilation! compilation, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.GeneratorDriver! | ||
| *REMOVED*Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Microsoft.CodeAnalysis.Compilation! compilation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.GeneratorDriver! | ||
| Microsoft.CodeAnalysis.GeneratorFilterContext | ||
| Microsoft.CodeAnalysis.GeneratorFilterContext.CancellationToken.get -> System.Threading.CancellationToken | ||
| Microsoft.CodeAnalysis.GeneratorFilterContext.Generator.get -> Microsoft.CodeAnalysis.ISourceGenerator! | ||
| Microsoft.CodeAnalysis.GeneratorFilterContext.GeneratorFilterContext() -> void | ||
| Microsoft.CodeAnalysis.IPropertySymbol.PartialDefinitionPart.get -> Microsoft.CodeAnalysis.IPropertySymbol? | ||
| Microsoft.CodeAnalysis.IPropertySymbol.PartialImplementationPart.get -> Microsoft.CodeAnalysis.IPropertySymbol? | ||
| Microsoft.CodeAnalysis.IPropertySymbol.IsPartialDefinition.get -> bool | ||
| Microsoft.CodeAnalysis.ITypeParameterSymbol.AllowsRefLikeType.get -> bool | ||
| Microsoft.CodeAnalysis.RuntimeCapability.ByRefLikeGenerics = 8 -> Microsoft.CodeAnalysis.RuntimeCapability | ||
| static Microsoft.CodeAnalysis.GeneratorExtensions.AsIncrementalGenerator(this Microsoft.CodeAnalysis.ISourceGenerator! sourceGenerator) -> Microsoft.CodeAnalysis.IIncrementalGenerator! | ||
| static Microsoft.CodeAnalysis.GeneratorExtensions.GetGeneratorType(this Microsoft.CodeAnalysis.IIncrementalGenerator! generator) -> System.Type! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,11 @@ namespace Microsoft.CodeAnalysis | |
| /// </summary> | ||
| internal sealed class SourceGeneratorAdaptor : IIncrementalGenerator | ||
| { | ||
| /// <summary> | ||
| /// A dummy extension that is used to indicate this adaptor was created outside of the driver. | ||
| /// </summary> | ||
| public const string DummySourceExtension = ".dummy"; | ||
|
|
||
| private readonly string _sourceExtension; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a value that is controllable by customers? If so have reservations about using a magic string. Had trouble tracking this through all the APIs to see where it originates.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's only created internally. We track the file extension because we actively parse the tree, so we need to pass it in from the outer driver when we wrap an ISourceGenerator. The generators on this path are never actually used directly, so we can just set it to anything. I chose a magic string so we can assert later on that it isn't used and dings us if we ever do allow it, so we know to fix it. At some point we should probably refactor these so the string isn't needed at all, but this just seemed simpler for now. |
||
|
|
||
| internal ISourceGenerator SourceGenerator { get; } | ||
|
|
@@ -27,6 +32,11 @@ public SourceGeneratorAdaptor(ISourceGenerator generator, string sourceExtension | |
|
|
||
| public void Initialize(IncrementalGeneratorInitializationContext context) | ||
| { | ||
| // We don't currently have any APIs that accept IIncrementalGenerator directly (even in construction we wrap and unwrap them) | ||
| // so it should be impossible to get here with a wrapper that was created via ISourceGenerator.AsIncrementalGenerator. | ||
| // If we ever do have such an API, we will need to make sure that the source extension is updated as part of adding it to the driver. | ||
| Debug.Assert(_sourceExtension != DummySourceExtension); | ||
|
|
||
| GeneratorInitializationContext generatorInitContext = new GeneratorInitializationContext(CancellationToken.None); | ||
| SourceGenerator.Initialize(generatorInitContext); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.