Skip to content
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 offset and end to NodeList #60261

Closed
FMorschel opened this issue Mar 6, 2025 · 3 comments
Closed

Add offset and end to NodeList #60261

FMorschel opened this issue Mar 6, 2025 · 3 comments
Labels
area-dart-model Use area-dart-model for issues related to packages analyzer, front_end, and kernel.

Comments

@FMorschel
Copy link
Contributor

Over at https://dart-review.googlesource.com/c/sdk/+/413520/comment/107d6345_854a2009/, @bwilkerson suggested:

We should maybe consider adding NodeList.offset, NodeList.length, and NodeList.end
You can use combinators.beginToken?.offset and combinators.endToken?.end to get this information.

At that CL, I made an extension for those values. Two things to have in mind here:

  • The list can be empty so offset and end should be nullable
  • There is already a length getter which means how many items we have inside the list. We should probably think of a better name for this length or not implement it since it can be easily calculated with the other two values. At the CL extension, I've named it nodesLength.
@lrhn lrhn added the area-dart-model Use area-dart-model for issues related to packages analyzer, front_end, and kernel. label Mar 6, 2025
@bwilkerson
Copy link
Member

Those two issues might well be why we didn't add these methods before. I'm thinking that we probably don't want to add them after all.

@FMorschel
Copy link
Contributor Author

FMorschel commented Mar 7, 2025

If we could say that the list can't ever be empty and use null in those cases (which is about the same, if we have no "list" of nodes in either case), we could assert offset/end. And that should always be enough to calculate the length.

@bwilkerson
Copy link
Member

True, but adding offset and end makes the NodeList look like it's an AstNode even though it isn't. It's then confusing when length has a different semantic. I think it's probably better the way it is, with a list-like interface rather than trying to make it more like an AstNode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model Use area-dart-model for issues related to packages analyzer, front_end, and kernel.
Projects
None yet
Development

No branches or pull requests

3 participants