sdk
sdk copied to clipboard
Analyzer `.dart_tool/build/generated` support fails in workspaces
See repro here
https://github.com/dart-lang/build/issues/3798#issuecomment-2943681937
the analyzer understands the .dart_tool/build/generated output folder used by build_runner, which lets you build+compile for web with build_runner, and the analyzer behind the IDE also understands and analyzes the output.
But, if you switch to a pub workspace, the analyzer can no longer find the generated output and so the IDE says there are errors due to missing files.
As discussed on chat, this support is in a weird place today: the dart compile command doesn't support .dart_tool/build/generated folder so it will not be able to compile the exact same code. It looks like we should build this out into a full feature whereby all the tools can find and work on generated output in a nice way.
But for people building web apps today, it would be good to have the workspace support match the non-workspace support, so that's what this issue is for.
Then I'll follow up later on the longer term :)
TIL that the analyzer can look inside .dart_tool/build/generated for sources imported with normal package: URIs!
While looking in the code to see how this worked because I was curious, I found that changing root here (which points at the workspace root):
https://github.com/dart-lang/sdk/blob/bddcddfe6b0914c7f234cd4400e1e70e8a72d374/pkg/analyzer/lib/src/workspace/pub.dart#L243-L252
To packages[packageName]!.rootFolder.path seemed to solve the analysis issue (ofc, it should be a variable and used in the if statement above to avoid the !), however I don't understand this functionality enough to know if it may require more than that (in case it needs to map paths in the opposite direction).
It was a surprise to me, too :)
Medium/long term I think we want to flesh this out as a full feature that is not so dependent on build_runner details and works across all the tools.
For now though I think it's just "fix the workspace issue noticed by a user"; pretty much, if for their build it analyzes without issues then that's good enough for now.