Skip to content

Include property names in debug description #1539

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 14, 2023

This adds child the name of child properties in the debug description inside parenthesis. E.g. for the following source code

switch foo {
  case 1:
    return "one"
}

we print the following:

SourceFileSyntax
├─CodeBlockItemListSyntax (statements)
│ ╰─CodeBlockItemSyntax
│   ╰─EnumDeclSyntax (item)
│     ├─keyword(SwiftSyntax.Keyword.enum) (enumKeyword)
│     ├─identifier("Foo") (identifier)
│     ╰─MemberDeclBlockSyntax (members)
│       ├─leftBrace (leftBrace)
│       ├─MemberDeclListSyntax (members)
│       │ ├─MemberDeclListItemSyntax
│       │ │ ╰─EnumCaseDeclSyntax (decl)
│       │ │   ├─keyword(SwiftSyntax.Keyword.case) (caseKeyword)
│       │ │   ╰─EnumCaseElementListSyntax (elements)
│       │ │     ╰─EnumCaseElementSyntax
│       │ │       ╰─identifier("first") (identifier)
│       │ ╰─MemberDeclListItemSyntax
│       │   ╰─EnumCaseDeclSyntax (decl)
│       │     ├─keyword(SwiftSyntax.Keyword.case) (caseKeyword)
│       │     ╰─EnumCaseElementListSyntax (elements)
│       │       ╰─EnumCaseElementSyntax
│       │         ╰─identifier("second") (identifier)
│       ╰─rightBrace (rightBrace)
╰─eof (eofToken)


I also considered adding the child name in front of the type but found the notation using parentheses more readable. If the consensus is that the prefix notation with : is better, I’m happy to change it.

SourceFileSyntax
├─statements: CodeBlockItemListSyntax
│ ╰─CodeBlockItemSyntax
│   ╰─item: EnumDeclSyntax
│     ├─enumKeyword: keyword(SwiftSyntax.Keyword.enum)
│     ├─identifier: identifier("Foo")
│     ╰─members: MemberDeclBlockSyntax
│       ├─leftBrace: leftBrace
│       ├─members: MemberDeclListSyntax
│       │ ├─MemberDeclListItemSyntax
│       │ │ ╰─decl: EnumCaseDeclSyntax
│       │ │   ├─caseKeyword: keyword(SwiftSyntax.Keyword.case)
│       │ │   ╰─elements: EnumCaseElementListSyntax
│       │ │     ╰─EnumCaseElementSyntax
│       │ │       ╰─identifier: identifier("first")
│       │ ╰─MemberDeclListItemSyntax
│       │   ╰─decl: EnumCaseDeclSyntax
│       │     ├─caseKeyword: keyword(SwiftSyntax.Keyword.case)
│       │     ╰─elements: EnumCaseElementListSyntax
│       │       ╰─EnumCaseElementSyntax
│       │         ╰─identifier: identifier("second")
│       ╰─rightBrace: rightBrace
╰─eofToken: eof

@ahoppen ahoppen requested review from rintaro and bnbarham April 14, 2023 01:47
@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

@swift-ci Please test

Copy link
Contributor

@kimdv kimdv left a comment

Choose a reason for hiding this comment

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

🥳

@ahoppen ahoppen force-pushed the ahoppen/include-child-name-in-debug-description branch from 85421cd to 087bb4a Compare April 14, 2023 15:58
@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

@swift-ci Please test Windows

@rintaro
Copy link
Member

rintaro commented Apr 14, 2023

I prefer prefix child name.
When you want to access some descendant from a given node, I feel it is more readable:

SourceFileSyntax
├─statements: CodeBlockItemListSyntax
│ ╰─[0]: CodeBlockItemSyntax
│   ╰─item: EnumDeclSyntax
│     ├─enumKeyword: keyword(SwiftSyntax.Keyword.enum)
│     ├─identifier: identifier("Foo")
│     ╰─memberBlock: MemberDeclBlockSyntax
│       ├─leftBrace: leftBrace
...

You can easily write node.statements[0].item.memberBlock without moving your gaze to the end of lines.

(Yes I'd like [n]: in collections)

@bnbarham
Copy link
Contributor

bnbarham commented Apr 14, 2023

Awesome!

I like the [n] idea. I don't have a strong preference for before/after. The : syntax has the advantage that () is already used so it seems less busy to me. But it's debugging text so I'd get used to either.

@ahoppen ahoppen mentioned this pull request Apr 14, 2023
@kimdv
Copy link
Contributor

kimdv commented Apr 14, 2023

@swift-ci please test windows

@ahoppen ahoppen force-pushed the ahoppen/include-child-name-in-debug-description branch from 087bb4a to d4edeb8 Compare April 14, 2023 22:08
@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

Thanks for the feedback. I updated the PR to include the child name as a prefix and use [0] etc for collections.

@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Apr 14, 2023

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Apr 15, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit aa65da5 into swiftlang:main Apr 15, 2023
@ahoppen ahoppen deleted the ahoppen/include-child-name-in-debug-description branch April 15, 2023 15:01
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Apr 18, 2023
…name-in-debug-description

Include property names in debug description
ahoppen added a commit to ahoppen/swift-syntax that referenced this pull request Apr 18, 2023
…name-in-debug-description

Include property names in debug description
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.

4 participants