Skip to content

streamline deeply nested CST snapshots#726

Merged
OmarTawfik merged 3 commits intoNomicFoundation:mainfrom
OmarTawfik-forks:combine-comments
Jan 10, 2024
Merged

streamline deeply nested CST snapshots#726
OmarTawfik merged 3 commits intoNomicFoundation:mainfrom
OmarTawfik-forks:combine-comments

Conversation

@OmarTawfik
Copy link
Copy Markdown
Contributor

Context: #698 (comment)

  • combined parents with a single child on the same line
  • using the unicode character instead of colon : to separate node name and kind, in order not to break YAML parsing/formatting.
  • surround entire nodes with parenthesis instead of just the kind, to make it easier to read.
  • include whitespace in the snapshots, since they now take less visual space, and it will make it easier to spot changes to trivia during development.

@OmarTawfik OmarTawfik requested a review from a team as a code owner January 2, 2024 19:22
@OmarTawfik OmarTawfik enabled auto-merge January 2, 2024 19:22
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 2, 2024

⚠️ No Changeset found

Latest commit: ed9a38e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@OmarTawfik OmarTawfik changed the title Combine-comments streamline deeply nested CST snapshots Jan 2, 2024
Copy link
Copy Markdown
Contributor

@Xanewok Xanewok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it and I have mixed feelings at the same time 😅

Flattened nodes is a great idea and I can see immediate benefit, but once we put more glyphs like the arrow, parentheses, the faux colon, I feel like I have to spent some cognitive budget to decipher it and since it's not uniform with the rest of the regular tree this makes it not obvious for me, yet. Maybe I'm just used to the old format and I'll have to get used to this one, as well?

Torn on putting everything in the parentheses. On one hand it's nice and feels a bit like the (name: type) syntax, but on the other, it feels lispy and like you'd want to nest it but we're stuck with YAML structure (confusing for me at first); the previous one I liked, because only the name was in parentheses and it felt like a good mix, because it's a) optional b) more of a hint, as the structure and the node type is the most important here.

I'm a fan of not omitting whitespace here, since it makes it more uniform and will help some catch some regressions (like the one I introduced for the error recovery, the other day).

I'll let @AntonyBlakey also take a look at this, maybe we can brainstorm a way to make it a bit easier to read.

In any case, great job!

@OmarTawfik
Copy link
Copy Markdown
Contributor Author

OmarTawfik commented Jan 4, 2024

@Xanewok thanks for taking a look!

Flattened nodes is a great idea and I can see immediate benefit, but once we put more glyphs like the arrow, parentheses, the faux colon, I feel like I have to spent some cognitive budget to decipher it and since it's not uniform with the rest of the regular tree this makes it not obvious for me, yet. Maybe I'm just used to the old format and I'll have to get used to this one, as well?

What do you mean by "regular tree"? you mean ASCII codes? I'm happy to use any other glyphs, as long as it is still valid YAML. In any case, I think we can give it a shot, as we can always change it later.

Torn on putting everything in the parentheses. On one hand it's nice and feels a bit like the (name: type) syntax, but on the other, it feels lispy and like you'd want to nest it but we're stuck with YAML structure (confusing for me at first); the previous one I liked, because only the name was in parentheses and it felt like a good mix, because it's a) optional b) more of a hint, as the structure and the node type is the most important here.

I think once we combine multiple ones on the same line, the fact it is optional is actually confusing, and makes it less clear how different nodes are separated. I suggest we still surround the entire node title (regardless of which metadata it has) with some delimiter. One other alternative is full-width square brackets (below). WDYT?

Tree:
  -[BreakStatement]: # 0..16 "break invalid ;\n"
      -[break_keyword꞉ BreakKeyword]: "break" # 0..5
      -[LeadingTrivia]--►[Whitespace]: " " # 5..6

@Xanewok
Copy link
Copy Markdown
Contributor

Xanewok commented Jan 4, 2024

What do you mean by "regular tree"?

I accidentally a word... I meant "regular tree (shape)". Sorry about that! Also, It seems I didn't complete the review by accident; it's a shame that these are only persisted locally... let me try to recreate a comment that I had.

- (close_brace) CloseBrace: "}" # 23..24
- (Block): # 0..24 "{ unchecked { x = 1; } }"
- (open_brace꞉ OpenBrace): "{" # 0..1
- (statements꞉ Statements) ► (item꞉ Statement) ► (variant꞉ UncheckedBlock): # 1..22 " unchecked { x = 1; }"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flattened path immediately makes sense to me for some terminal path

- (LeadingTrivia) ► (Whitespace): " " # 5..6

but when used in a non-terminal path/a node that has children it's confusing for me, for whatever reason. Maybe it's because it combines quite a bit of glyphs/sigils but also contains rendered children content that may be mistook visually for YAML string value? i.e. # 1..22 " unchecked { x = 1; }" Maybe using different characters like 《content》to disambiguate would help?

I also tried to experiment with piggy-backing on the file structure shorthand forms (used in GitHub interface, VS Code): some/node but the name metadata makes this significantly harder to read.

I don't have more alternatives and I know this is subjective...

Alternatively, maybe we could at first only enable the flattened/shorthand path for terminal paths/nodes and see if it's good enough for now?
This would keep the tree layout consistent, i.e. disallow following confusing structure:

- parent
    - child > grandchild:
        - great_grandchild: "value"
    - child:
        - grandchild: "value"

Or maybe doing this not only for terminals as per above but also for always-single-child-nodes (enums) but not for lists/other with 1 child would strike a better balance here?

For example, this might be too big of a shortcut that IMO hurts rather than improves readability:

- (items꞉ TupleValues) ► (item꞉ TupleValue) ► (expression꞉ Expression) ► (variant꞉ EqualityExpression): # 1..11 "foo == bar"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe using different characters like 《content》to disambiguate would help?

I like those alternative delimiters. But then I did spend years writing APL, so ... :)

@AntonyBlakey
Copy link
Copy Markdown
Contributor

I think once we combine multiple ones on the same line, the fact it is optional is actually confusing, and makes it less clear how different nodes are separated. I suggest we still surround the entire node title (regardless of which metadata it has) with some delimiter. One other alternative is full-width square brackets (below). WDYT?

I like the regularity of always enclosing, even when there is no label. I love the arrow chars. I'm not keen on the colons that look-like-but-actually-are-some-weird-unicode colons. I think the square brackets are better. But these are all aesthetic opinions.

@OmarTawfik OmarTawfik added this pull request to the merge queue Jan 10, 2024
Merged via the queue into NomicFoundation:main with commit ffc4ac5 Jan 10, 2024
@OmarTawfik OmarTawfik deleted the combine-comments branch January 10, 2024 16:30
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.

3 participants