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 an assist/refactor to remove a function tear-off #52863

Open
rrousselGit opened this issue Jul 6, 2023 · 2 comments
Open

Add an assist/refactor to remove a function tear-off #52863

rrousselGit opened this issue Jul 6, 2023 · 2 comments
Labels
analyzer-assist Issues with analysis server assists area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@rrousselGit
Copy link

Hello!

One of Dart's feature is the ability to pass a function identifier to another function as argument, such as:

list.map(callback);

But it's not uncommon that after some changes, our callback now expects two arguments. Meaning we have to remove the tear-off to write instead:

list.map((e) => callback(e, anotherParam));

Similar to how we have a "replace function literal with tear-off" refactor, it would be nice to have a "replace tear-off with function literal".
This would enable quickly doing a back-and-forth between both options depending on how the code evolves

@bwilkerson
Copy link
Member

I could easily see an assist to convert

list.map(callback);

to

list.map((e) => callback(e));

and we could easily detect when the tear-off required more parameters, but how would we know what the other arguments ought to be?

@bwilkerson bwilkerson added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug analyzer-assist Issues with analysis server assists labels Jul 6, 2023
@rrousselGit
Copy link
Author

I would assume that the refactor would specify the new arguments. It would simply unwrap the tear-off, and have users specify the new arguments themselves.

@scheglov scheglov added the P3 A lower priority bug or feature request label Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-assist Issues with analysis server assists area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. 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