Skip to content

Introduce a source accurate and structural view of a SwiftSyntax tree #522

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

Merged
merged 1 commit into from
Aug 1, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 27, 2022

SyntaxTreeViewMode allows two different views on a SwiftSyntax tree:

  1. Either a purely sourceAccurate view, which skips over all missing children but traverses garbage syntax (once implemented). This mode is intended for clients that operate at the source code level, like swift-format
  2. For clients that don’t care about 100% about source fidelity but would like to view the syntax tree for structural analysis with fixes from the parser applied, there’s the fixedUp view. This includes missing nodes (because the user probably meant to write these) and skips over garbage nodes (because the client will likely have a hard time reasoning about these nodes if the parser couldn’t make sense of them)

@ahoppen
Copy link
Member Author

ahoppen commented Jul 27, 2022

swiftlang/swift-stress-tester#181

@swift-ci Please test

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

I think it'd be nice if we kept the original API as well and just had it default to .sourceAccurate. Fewer changes in all the clients that way. But I like the additions in general - I had done the NonNilRawSyntaxChildren in my own changes 😅.

@ahoppen ahoppen force-pushed the pr/syntax-tree-view-mode branch from 714ab5e to 3dd2e2b Compare July 28, 2022 08:04
@ahoppen
Copy link
Member Author

ahoppen commented Jul 28, 2022

I made two changes to the PR:

  • Renamed the parameters from syntaxTreeViewMode to viewMode (if you’ve got better ideas for naming, I’m open to suggestions)
  • Added the firstToken etc. getters on Syntax again. These default to the source accurate view.

@ahoppen
Copy link
Member Author

ahoppen commented Jul 28, 2022

swiftlang/swift-stress-tester#181

@swift-ci Please test

@ahoppen ahoppen force-pushed the pr/syntax-tree-view-mode branch from 3dd2e2b to 3ef5682 Compare July 28, 2022 13:56
@ahoppen
Copy link
Member Author

ahoppen commented Jul 28, 2022

swiftlang/swift-stress-tester#181

@swift-ci Please test

`SyntaxTreeViewMode` allows two different views on a SwiftSyntax tree:

1. Either a purely `sourceAccurate` view, which skips over all missing children but traverses garbage syntax (once implemented). This mode is intended for clients that operate at the source code level, like swift-format
2. For clients that don’t care about 100% about source fidelity but would like to view the syntax tree for structural analysis with fixes from the parser applied, there’s the `fixedUp` view. This includes missing nodes (because the user probably meant to write these) and skips over garbage nodes (because the client will likely have a hard time reasoning about these nodes if the parser couldn’t make sense of them)
@ahoppen ahoppen force-pushed the pr/syntax-tree-view-mode branch from 3ef5682 to cd7ded2 Compare July 29, 2022 20:21
@ahoppen
Copy link
Member Author

ahoppen commented Jul 29, 2022

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Aug 1, 2022

swiftlang/swift-stress-tester#181

@swift-ci Please test

@ahoppen ahoppen merged commit c9042c0 into swiftlang:main Aug 1, 2022
@ahoppen ahoppen deleted the pr/syntax-tree-view-mode branch August 1, 2022 12:49
@fwcd
Copy link
Member

fwcd commented Aug 1, 2022

I think this PR accidentally reverted the rename from Examples to Snippets in #477.

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