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

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

Closed
ByronMayne opened this issue Nov 7, 2023 · 3 comments

Comments

@ByronMayne
Copy link
Owner

ByronMayne commented Nov 7, 2023

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
Copy link

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
Copy link
Owner Author

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants