-
Notifications
You must be signed in to change notification settings - Fork 256
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
Add support for IIncrementalGenerator
#941
Comments
Great! Thank you! I'll try it out over next weekend. |
And I got my I didn't know about the combination of
Thank you very much @sharwell for the example! |
I think it should now be safe to use 4.0.1 on Microsoft.CodeAnalysis.CSharp.Workspaces due to .NET 6 LTS and .NET 5 being close to EOL. Besides I do not think many are using the .NET 5 SDK anymore and are instead using the .NET 6 or newer SDK and targeting .NET 5 making it able to use generators using v4.0.1 of the roslyn packages without issues because they will be using a newer compiler that uses those versions anyway. |
For
ISourceGenerator
that were introduced in3.8
, I was able to adopt theMicrosoft.CodeAnalysis.CSharp.SourceGenerators.Testing.[Test-Framework]
package quickly, since I'm also familiar with theAnalyzer
/CodeFix
/CodeRefactoring
variants.Now I would love to see an
IncrementalGenerators
variant.An alternative would be to add support for
IIncrementalGenerator
to the already existingSourceGenerators
package, but I guess this is not preferable since the update of the dependencyMicrosoft.CodeAnalysis.CSharp.Workspaces
to4.0.1
would be a breaking change for existing consumers.I built a custom testing helpers (inspired by the Source Generators Cookbook), which are continuously growing (across my source generator projects), but are missing the really powerful features such as
ReferenceAssemblies
and{|#0:Location|}
-Syntax.I also noticed #933, but if I understand correctly, then
IIncrementalGenerator
are not suppored byMicrosoft.CodeAnalysis.Testing
, because the genericCSharpSourceGeneratorVerifier
andCSharpSourceGeneratorTest
types are constrained toISourceGenerator, new()
.I also tried to apply the
ISourceGenerator
-types from Microsoft.CodeAnalysis.Testing, and then useCSharpSourceGeneratorTest
with a custom IncrementalGenerator-to-SourceGenerator-wrapper. But this approach failed, because the methods of the instance returned by Microsoft.CodeAnalysis.GeneratorExtensions.AsSourceGenerator() throw anInvalidOperationException
with messageThis program location is thought to be unreachable.
. I have just learnt that theCSharpGeneratorDriver
unwraps that type again and does not use it directly.Here's a link this failed experiment: https://github.com/Flash0ver/F0.Compatibility/blob/test/microsoft-codeanalysis-testing/src/tests/F0.Compatibility.Generator.Tests/Testing/CSharpIncrementalGeneratorVerifier.Test.cs
The text was updated successfully, but these errors were encountered: