Skip to content

add support for generating common functions (copyWith, to/fromMap, to/fromJson) #48971

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

Open
Tracked by #55825
pq opened this issue May 6, 2022 · 4 comments
Open
Tracked by #55825
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-refactoring Issues with analysis server refactorings P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@pq
Copy link
Member

pq commented May 6, 2022

Form a discussion on flutter-insiders:

Some common things could be included too in the Generate... menu, like the copyWith method or the toMap, fromMap (from and to json)

Currently the "Generate..." menu produces this in IntelliJ

image

@DanTup: do we have similar support in VSCode?

(And are these current menu items implementing in IntelliJ or server-provided?)

/cc @stevemessick

@pq pq added legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request devexp-refactoring Issues with analysis server refactorings type-enhancement A request for a change that isn't a bug analyzer-editing-experience labels May 6, 2022
@DanTup
Copy link
Collaborator

DanTup commented May 6, 2022

We don't have anything like this in VS Code right now (because it would be hard to do reliable in VS Code versus the server). It does come up now and then though - it'd be awesome to support :-)

@bwilkerson
Copy link
Member

Would these be appropriate for snippets, or would they be better as commands?

@DanTup
Copy link
Collaborator

DanTup commented May 7, 2022

Yeah, I think snippets (eg. code completion) could be a good place for them. If the goal is for them to be used in both editors, we'd need to add support for snippets to the original protocol.

It could also be useful to have a way to re-generate them if you add new fields (perhaps as an assist on the method?).

I also wonder if there's any overlap with static metaprogramming - some of the things above are specifically noted as use cases in that issue. I can see reasons for both (being able to have invisible generated code, or having them visible in the code for simplicity, or being able to generate a basic implementation to customise), but I wonder if there should be some relationship between them (for example, might it be useful to "inline" some code that was previously being generated with static meta programming to customise, and could/should these snippets be driven by that?).

@bwilkerson
Copy link
Member

If the goal is for them to be used in both editors, we'd need to add support for snippets to the original protocol.

@jwren We'll need to talk to Alex and get a clear direction for where we want this to go in IntelliJ, but if we do nothing else we could always return them as code completions the way we're doing in LSP.

I also wonder if there's any overlap with static metaprogramming ...

Yes, absolutely. This is one of the use cases that static metaprogramming would support. That proposal has the advantage that the methods would automatically be kept up to date.

That said, Dart team hasn't yet decided whether static metaprogramming will be approved and supported, and even if it is, I expect it will take a while for it to be implemented. It might well be worthwhile for us to support some of the more common cases in the meantime.

@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. analyzer-editing-experience labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-refactoring Issues with analysis server refactorings P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants