-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add Model.qualifiedNameOfMember, add fast way to find the path to JsonBufferBuilder #87
Conversation
/// | ||
/// TODO(davidmorgan): this works for any node, but it's not clear yet which types of | ||
/// node we want this functionality exposed for. | ||
/// TODO(davidmorgan): a list of path segments is probably more useful than `String`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to this comment, what is the format of the String? Dot separated paths? What are you intended to do with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the PR opening post, there is no specific use case yet :)
This was prompted by your suggestion that if a Member
knows where it is in the tree, you can fully generate code referencing it. So the anticipated use case is for the augmentation builders/helpers.
I guess the first use case will change the format to something actually useful :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think specifically, we just want to be able to get a qualified name for any given member? Can this just return that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/// TODO(davidmorgan): a list of path segments is probably more useful than `String`. | ||
String? pathToMember(Member member) => _pathTo(member.node); | ||
|
||
/// Returns the path in the model to [node], or `null` if [node] is not in this `Model`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns the path in the model to [node], or `null` if [node] is not in this `Model`. | |
/// Returns the path in the model to [node], or `null` if [node] is not in this [Model]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -39,3 +39,13 @@ class _IteratorFunctionIterable<T> extends Iterable<T> { | |||
@override | |||
Iterator<T> get iterator => _function(); | |||
} | |||
|
|||
/// A `Map` in a `JsonBufferBuilder`. | |||
abstract interface class MapInBuffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw we could also use Expandos for this, which would also allow us to record parents for other types of maps (and wouldn't need this extra interface and associated type checks).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks.
Another way to tweak would be to lean on the type more, the parent of a map in a buffer is definitely also a map in a buffer. So there should only be one type check to get the whole path. (And as noted elsewhere, we should store the key used as well as the parent, so it really is fast).
pkgs/dart_model/test/model_test.dart
Outdated
final member = model.uris['package:dart_model/dart_model.dart']! | ||
.scopes['JsonData']!.members['_root']!; | ||
expect(model.pathToMember(member), | ||
'/uris/package:dart_model/dart_model.dart/scopes/JsonData/members/_root'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like a very useful path, how are you supposed to parse out the library URI? What is the intended use case for these paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned elsewhere :) indeed I expect it will change to path segments or maybe something even more specific like a lookup of exactly library URI.
It is intended for augmentation builders which we don't have quite yet :)
Per our discussion--will update to QualifiedName as suggested before merging. Thanks :) |
1b50388
to
ad92034
Compare
For #72, this seems reasonably convincing that we can get the path to a node cheaply, which means we don't have to add it everywhere explicitly in the schema.
This doesn't add a use case yet, probably there will be some tweaks when there is a first use case; one specific note is that the link to parent could also store the key in the parent, which would avoid the search through parent's keys that currently happens. But that's easy to change later.