-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Omit part 'file.g.dart'; When defined in build.yaml #60016
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
Comments
This combined with augments and the "build_runner watch" command would give us 99% of the functionality of macros |
Without macros, augments aren't enough to remove the need for a "part" definition. Although for augments, the syntax is slightly different So this is useful even with augments |
Related: dart-lang/language#1958 |
The main argument against this seems to be the necessity to scan every file to see if it's linked to another one, but if we treat dropping the "part" command as a convenience feature, than we would only need to scan the files that share the same location and root name. IE EDIT: Since the only side effect of being accidently included is that they have access to the other files private variables, we could also drop the "part of" directive for any of the basename.*.dart files. This would make it easier for users to split up complex files and save us a file scan to look for "part of" |
Explicit part statements are a good thing imo and should stay, for a variety of reasons:
Ultimately you would end up paying a significant cost for this on every build which is ultimately much more than the cost of simply writing the This would also very significantly affect build_runner performance, as in make it orders of magnitude slower. The speed of it currently is already n^2 based on the number of transitive library dependencies, and this would be multiplying the |
@jakemac53 In theory, couldn't we have a file (or several) in .dart_tool containing a map of part directives? That way, every time the builders run, it updates this file to specify which files are linked, ensuring that compilers always watch the files they are aware of. |
If I had to Cmd+Click the |
@jakemac53 this was a very fast decision... and not in a good way |
Wouldn't be possible to cache all files in-memory and monitor project directories by listens for filesystem events? That way a new file can be loaded when it's created. No need to list the entire file system surrounding all known files on every incremental rebuild.
Indexing all files (in-memory) by path+basename should make navigating to all the parts (under same path) straightforward. Navigating to any part file for partial classes in C# works even though files can be in different directories. IDE lists all files when invoking go to declaration command. Probably by resolving and indexing all namespace+type_names inside each file. |
These are valid points for not using the build.yaml to derive part files. We don't have to solve the problem in that particular way, but there are other solutions for auto-deriving part file.g.dart especially for super local files.
|
Currently, when using code generation in Dart, we need to explicitly include part 'file.g.dart'; in the source file. However, this requirement is redundant when the corresponding .g.dart file is already declared in build.yaml.
I propose an enhancement where the Dart build system automatically recognizes generated files based on build.yaml, eliminating the need for the part directive in the source code.
EDIT:
To make the included
part
files visible to the end user and prevent unintendedpart-of
declarations, the analyzer could display a link at the top of the original file: "Show part files". Clicking this link would expand a block listing all the automatically addedpart
directives.The text was updated successfully, but these errors were encountered: