ByronMayne / SourceGenerator.Foundations

A Source Generator for Source Generators. Gives out of the box support for transistent dependencies and logging right in Visual Studio
MIT License
31 stars 0 forks source link

Add analyzer to validate the source generators have a default constructor. #11

Closed ByronMayne closed 7 months ago

ByronMayne commented 11 months ago

When auto implementing the base class IncrementalGenerator the constructor that it generates is invalid

 [Generator]
 internal class MyGenerator: IncrementalGenerator
 {             
      public MyGenerator(string? name) : base(name) 
                         ^^^^^^^^^^^^^  <!-- Show error here saying you must provide default
      {}
}

What the user should do is call the base with a hard coded value

 [Generator]
 internal class MyGenerator: IncrementalGenerator
 {             
      public MyGenerator() : base("MyGenerator") 
      {}
}
BlueManiac commented 7 months ago

I missed this after copilot created a faulty constructor. Result is that the source generator stops working without any indication on what's wrong.

I realized it after about 5 minutes, but it's an annoyance.

Thanks for working on this!

ByronMayne commented 7 months ago

I figured this would burn someone at some point, but I have zero visibility on if anyone is actually using the library. I would be interested in getting your feedback if you end up using it. This has been a super tough project to get working due and the api has been a bit... malleable.

ByronMayne commented 7 months ago

Created a PR for this that checks for this along with two other common mistakes