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

Improvements for generator authors #3824

Open
davidmorgan opened this issue Feb 4, 2025 · 5 comments
Open

Improvements for generator authors #3824

davidmorgan opened this issue Feb 4, 2025 · 5 comments
Assignees
Labels
type-enhancement A request for a change that isn't a bug

Comments

@davidmorgan
Copy link
Contributor

Overall tracking issue for quality of life improvements for generator authors.

For example this comment "... lack of documentation ... certain things we're likely to want or need are not evident".

@davidmorgan davidmorgan added the type-enhancement A request for a change that isn't a bug label Feb 4, 2025
@davidmorgan davidmorgan self-assigned this Feb 4, 2025
@TekExplorer
Copy link

Yeah. For example;
what is all the "2" stuff? why does it matter? whats the difference?
how can i look up a package? a specific class? how do tell if a class is imported already?
how do i work with DartType? (TypeVistor!) how do deal with type parameters? DartType's are instantiated types right? that means if there's any parameters, they are specified, even if its with dynamic right?
do elements specify type parameters? elements are to Future what DartType is to Future<T> right?
can i turn an annotation into the actual object? if so how? (otherwise i dynamically work with DartObject i presume. probably want an extension type. might even want a generator for that too)
what even is NullabilitySuffix.star?

and one of the most important: how do i turn this (type) into code?

I imagine most of that can be answered with proper documentation, and improved api can be made later, possibly through wrappers or improving the api directly

@jakemac53
Copy link
Contributor

Note that the APIs discussed in the linked comment are analyzer APIs and not directly related to this package. So, something should probably be filed on the analyzer if we want those APIs to be more well documented.

@rrousselGit
Copy link

It's related. Writing generated can be though in part because Analyzer needs to be learned.

But in terms of code-gen, I think APIs are that crutially missing are:

  • A way to make it simpler to deal with import prefixes
  • Something to insert a DartType in the generated code (getDisplayString is not recommended for this, but we have nothing else) (it should have proper prefix support too)

As it is, we can inspect code, but we don't have any help for writing code

@TekExplorer
Copy link

It's related. Writing generated can be though in part because Analyzer needs to be learned.

But in terms of code-gen, I think APIs are that crutially missing are:

  • A way to make it simpler to deal with import prefixes

Actually not really necessary since parts can have imports now, so we can just sort of ignore that.

  • Something to insert a DartType in the generated code (getDisplayString is not recommended for this, but we have nothing else) (it should have proper prefix support too)

Yes!
I think I've managed to make a utility that converts a dart type into a code_builder reference, but if you aren't using code builder, it can be really annoying.

As it is, we can inspect code, but we don't have any help for writing code

Yup!

@davidmorgan
Copy link
Contributor Author

Code to support writing generators sounds good to me.

It would probably make sense to pull source_gen into the new build_runner effort.

Performance first :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants