-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Dart quick fix of moving generated function to another file should move in the "part 'file.g.dart' " as well #55097
Comments
Is the original library (the one containing the declaration before it's moved) being imported by the newly created library (that is, is If not, then I think that adding an import for the original library is the real solution. It's absolutely true that the newly created library needs to import the original library if the code being moved references something from the original library that isn't also being moved. The bug is probably that we're not considering declarations in the original library that come from part files when deciding whether to add an import of the original library. But I think that moving the part file is probably the wrong solution. It would be good if we could recognize that the
I'd love to automate more of this process but I don't think we have enough information to be able to do so at this point. Also, we should evaluate whether macros will solve this problem before putting too much effort into a solution. |
Apologies, I had a slight oversight. What happened is that the build runner wasn't running on watch, so moving the file did when work So basically if you move a generated function to a new file, the .g file will stay there, and the original file will also stay there and only contain imports and the part. Here's a function in a standalone file called import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'test_function.g.dart';
@riverpod
String testFunction(TestFunctionRef ref) => 'A String'; The code when moving the function into a file called // this file is test_function_two.dart
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:salam_app/utils/test_function.dart'; //
// Function doesn't give error because it imports the generated file
@riverpod
String testFunction(TestFunctionRef ref) => 'A String'; Then only these lines are left in the original file of import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:the_app/test_function_two.dart'; // Not sure why it imports the file after moving the function
part 'test_function.g.dart'; However when build runner is running on watchThen |
I agree that this is a bad experience, and I'd love to make it better. Unfortunately, our tools have no way of knowing the behavior of any given code generator, or even whether a code generator is being used to generate a file, so it isn't clear what we can do in this situation. |
This tracker is for issues related to:
Clicking on quick fix then move to file only moves the required imports but doesn't move
part 'application_support_directory_provider.g.dart'
Of which the imports and part looks like after moving file (the image has
part
added manually):Current behaviour:
Expected behaviour:
import 'dart:io'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +part 'application_support_directory_provider.g.dart';
The text was updated successfully, but these errors were encountered: