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

Fix tree node start and end locations #2084

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

milesziemer
Copy link
Contributor

Some tree types are guaranteed to have certain children, even if those children are empty. For example, SHAPE_STATEMENT always has a TRAIT_STATEMENT as its first child. Since trees with children have their start/end line and column locations computed from the respective locations of their first and last child, trees with 0 children ("empty" trees) will have a location of (0,0)-(0,0). If an empty child is the first or last child of its parent, the 0 location will bubble up to that parent.

This commit changes the way start/end line and column locations are computed for trees with children, such that empty children are ignored. This required a change to use statement sorting, which relied on the 0 location bubbling up to the parent to indicate to the formatter whether the use statement has a line comment.

Additional tests were added for the formatter and tree location computation. TokenTreeLeaf toString was also updated to include tree location, useful for debugging purposes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Some tree types are guaranteed to have certain children, even if
those children are empty. For example, SHAPE_STATEMENT always has
a TRAIT_STATEMENT as its first child. Since trees with children
have their start/end line and column locations computed from the
respective locations of their first and last child, trees with 0
children ("empty" trees) will have a location of (0,0)-(0,0). If
an empty child is the first or last child of its parent, the 0
location will bubble up to that parent.

This commit changes the way start/end line and column locations
are computed for trees with children, such that empty children
are ignored. This required a change to use statement sorting,
which relied on the 0 location bubbling up to the parent to
indicate to the formatter whether the use statement has a line
comment.

Additional tests were added for the formatter and tree location
computation. TokenTreeLeaf toString was also updated to include
tree location, useful for debugging purposes.
@milesziemer milesziemer requested a review from a team as a code owner December 23, 2023 16:35
@milesziemer milesziemer requested a review from kstich December 23, 2023 16:35
@milesziemer milesziemer merged commit eaac0c2 into smithy-lang:main Jan 4, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants