-
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
VM Service's lookupResolvedPackageUris returns different org-dartlang-sdk structure for Flutter apps from Dart #49863
Comments
Hm, it looks like the |
The problem with looking for We could override this in the Flutter DAP if we can assume that it would always be @johnniwinther do you know if the difference described above is intended, or do you know who I could ask? |
This could be related to the difference in build rules used to compile platform dill files: For standalone Dart SDK: Lines 182 to 183 in 56df821
For Flutter: In the first case root directory for Note that there are also separate build rules for building platform dill files for dart2js, DDC, dart2wasm as well as Fuchsia-specific Flutter runner and Dart runner. We might also have a separate copy of those build rules in g3 (as it doesn't use |
Also note that in case of Flutter some libraries come from Dart SDK and have |
@alexmarkov do you know whether this is deliberate or a side-effect of the paths being set for another reason? If deliberate, is it reasonable/feasible to have them documented somewhere (can they be relied on to never change)? The debug adapter needs a reliable way to map between paths that exist on the users file system and Dart's URIs to correctly handle breakpoints and stepping with the debugger. My original understanding was that |
Ah, that's good to know - I had assumed everything from Flutter was going to be |
@alexmarkov @bkonyi can anyone confirm whether this difference is deliberate or accidental? I'd really like to fix this (breakpoints in SDKs have been a long-standing issue and we seem very close to fixing it), but I don't want to add more hard-coded assumptions into DAP without some confirmation that this is expected (and ideally, a full set of these mappings so the client can handle them correctly). |
@DanTup These different paths just reflect different directory layouts we have while building Dart SDK and Flutter engine, so they are deliberate. As far as I know internal google repo uses a yet another directory layout. I think it's not safe to assume particular directory layout relative to Maybe we can avoid these assumptions by cutting leading directory parts from |
Yeah, that was my concern. I'd like to get to something stable so we can have this issue resolved once and for all.
This doesn't feel like a particularly great solution. When the debugger breaks and we (the IDE/debug adapter) get a call stack, we may need to translate a large number of URIs/paths in one go. We're already having to send them to the VM to be converted to I'm also not sure whether this covers all cases. I don't have any visibility of what schemes and paths can be returned here (whether there may be other paths we're not handling). It would be ideal if there was some documentation about exactly what URIs can be returned from I guess this is slightly related to #48435 which I think is asking for an abstraction over this API that handles this (eg., it always just provides file paths/URIs for all inputs, whether they're |
In the interest of providing a fix for this in the near-term, I'm going to look at handling the specific values above in the Flutter DAP. I'll make sure it doesn't fail if this ever changes (it will just fail to map - the same thing it already does today with those paths) and we can revisit it if it does (or if we get something better). I chatted with @bkonyi briefly and he suggested that one option could be for the compilation tooling to accept an option to specify where the Dart SDK root is relative to the embedding projects root, which could allow this to be consistent (at which point perhaps consistency could become a "promise"). I don't know how involved that is (or whether it could impact other things) - any thoughts @alexmarkov? |
Currently, when compiling platform, we specify real directory of Note that different embeddings of Dart have their own @DanTup Could you clarify how the proposed option would be taken into account and how it would help? My understanding is that if we would like to rely on a particular value of URIs of platform libraries, then we would need to unify directory layout when building platform in all projects embedding Dart (so that |
Sorry for the wall of text, but some context because it might not be completely clear what all of this relates to from the above :-) Since forever, if a user VS Code clicked Go-to-Definition on a symbol that led to the SDK, the analysis server would return a file path to the local SDK sources on their disk. If they added a breakpoint in that file, VS Code would send that path to the Dart VM during debug sessions, but the breakpoint would not work (because the running VM doesn't know that path corresponds to the SDK). (the same was true for package files, although that was fixed some time ago, and the running VM was able to them). To fix this (or so I thought) some new VM Service APIs were added to map URIs to/from file paths. However, it turned out that this API couldn't map the SDK sources, it could only convert them from So, in the debug adapter (which sits between VS Code's debugger and the VM Service) we have mapping that can convert a URI in the form It turned out this translation of This may not be a complete fix (we don't handle anything outside of Of course, it would be nice to implement a more complete/more static version (which I guess is what #48435 is about.. removing the need from the "client" - in this case the debug adapter - from needing to handle the |
Re-reading the above, I noticed you gave another example:
So my fix above is probably incomplete and instead of just allowing a single Dart SDK URI to be overridden, it should probably be a collection of mappings. How much it's worth trying to cover all cases probably depends on how long this code is likely to live until there may be something better though. |
Sorry, I think I misunderstood and I explained how my short-term fix would work and not what I wrote after discussing with @bkonyi. Re-reading what you wrote, I'm less certain about how this would work, but now I'm not sure whether Ben meant for these URIs to be consistent, or that the DAP would have a way to access that relative path to the Dart SDK. Perhaps focusing on the Dart SDK is not the right thing (because of things like |
…source files found by the analyzer Fixes Dart-Code/Dart-Code#4128. Also related: - dart-lang/sdk#49863 - dart-lang/sdk#48435
I'm not sure whether this is expected - if so, I think it needs documenting (it may already be, but I've not been able to find anything).
The DAP implementations use the VM Service's
lookupResolvedPackageUris
call to convert URIs likedart:code/uri.dart
(which are provided in stack traces) to things that can be mapped to local file paths on the users machine (so that when debug stepping, the same files can be opened that the user gets if they use Go-to-Definition via the analyzer).If I write code like this, and step into
Uri.parse
:Then in the Dart SDK,
lookupResolvedPackageUris
converts this URI toorg-dartlang-sdk:///sdk/lib/core/uri.dart
Currently, the debug adapters assumed that
org-dartlang-sdk:///sdk
points to the root of the Dart SDK and correctly map this to thelib/code/uri.dart
file in the Dart SDK (/sdk
is one example given in the docs).However, when running a Flutter app (using latest master) the result is
org-dartlang-sdk:///third_party/dart/sdk/lib/core/uri.dart
:I could update the code to also assume
org-dartlang-sdk:///third_party/dart/sdk
should map to the root of the Dart SDK, however it makes me wonder whether there may be other differences that need to be accounted for. I don't know how the mapping fororg-dartlang-sdk
is built, but it would make sense to ensure any assumptions in the DAP match the actual rules (and include a note in the code where those rules can be found).@bkonyi do you know if this is intended, and/or where the rules for
org-dartlang-sdk
are?The text was updated successfully, but these errors were encountered: