Comments (3)
Is the original library (the one containing the declaration before it's moved) being imported by the newly created library (that is, is utils/application_support_directory_provider.dart
the original library)? I'm guessing the answer is 'no' because otherwise you probably wouldn't have added the part directive by hand, but wanted to ask rather than make an assumption.
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 @riverpod
annotation is used by a code generator so that we could add the part
directive in the new file, but we don't currently have enough information to be able to do that. I suspect that the best workflow we can support for this kind of situation is:
- Select the declaration to be moved and invoke the 'move to file' refactoring.
- Run the code generator to create the new generated file and to update the old generated file (unless it's no longer needed).
- Add the
part
directive for the new generated file. - Remove the import of the original library if it's no longer needed.
- Remove the old generated file and it's associated
part
directive if the file is no longer needed.
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.
from sdk.
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.
from sdk.
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 build runner
is not running, at the expense that 2 files were left as is, the generated file and the original file which now only contains imports(presumably for the generated file) and the "part file.g.dart"
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 test_function.dart
before moving.
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 test_function_two.dart
// 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 test_function.dart
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 watch
Then test_function.dart
file gets messed up as there's no annotation but there's part
and it deletes the generated file, so function that was moved to test_function_two.dart
doesn't work anymore unless we add the part.
from sdk.
Related Issues (20)
- Bug: `Directory.watch()` emits incorrect `isDirectory` HOT 1
- Analyzer Feedback from IntelliJ
- Analyzer Feedback from IntelliJ
- Failures on [ DDS ] Don't await getIsolate calls in DDS initialization
- Changelog in stable branch does not match main version for 3.3.0 HOT 1
- bug using redirecting constructor in initializer of extension type HOT 11
- [vm] AppJIT snapshot loses ImmutableBit of objects HOT 2
- VmService.getPerfettoVMTimelineWithCpuSamples is slow HOT 1
- Cannot rename fields in object literal constructors HOT 2
- Crash trying to compile a flutter app with macros HOT 8
- [dart2wasm]: Incorrect assignment of the variable `dartInstance` in the output.mjs HOT 2
- [js_interop] should interpret a set of named parameters in dart as the last parameter in JS HOT 3
- Failures on [analyzer,frontend_server] Support nested macro compilation in binary protocol HOT 7
- warning: This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: NotificationListScreen.notificationList, NotificationListScreen.onItemTap, NotificationListScreen.seenUnseen (must_be_immutable at [adil_api] lib\main.dart:673)Analyzer Feedback from IntelliJ HOT 1
- warning: This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: NotificationListScreen.notificationList, NotificationListScreen.onItemTap, NotificationListScreen.seenUnseen (must_be_immutable at [fjfj] lib\main.dart:673)Create an issue HOT 1
- Parse failure for broken augmentation library
- `$HOME/.dart-tool` issue HOT 12
- "Extract method" fails when there are external variables, but the variables are not named
- Nullable extension types are wonky HOT 4
- Analyzer Feedback from IntelliJ
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.