Skip to content

Audit public API on SyntaxProtocol #1912

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 4 commits into from
Jul 23, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 17, 2023

First, re-arrange the properties in SyntaxProtocol to group them logically.

Then, I found two areas of improvement:

  • Deprecated isImplicit
    • This property seems to be pretty useless and probably dates back to a completely different design of the syntax tree where implicit nodes were a thing.
  • Clean up position/range API on SyntaxProtocol
    • The position and range API on SyntaxProtocol was a little inconsistent and misleading. Clean it up so that we have totalLength (including trivia), contentLength (excluding trivia) and a matching pair for byteRange.

ahoppen added 2 commits July 17, 2023 07:06
This gives the file a little order and makes it easier to spot naming inconsistencies.
This property seems to be pretty useless and probably dates back to a completely different design of the syntax tree where implicit nodes were a thing.
@ahoppen ahoppen requested a review from bnbarham July 17, 2023 14:07
@ahoppen
Copy link
Member Author

ahoppen commented Jul 17, 2023

@swift-ci Please test

The position and range API on `SyntaxProtocol` was a little inconsistent and misleading. Clean it up so that we have `totalLength` (including trivia), `contentLength` (excluding trivia) and a matching pair for `byteRange`.
@ahoppen ahoppen force-pushed the ahoppen/syntaxprotocol-api branch from 0de6b19 to 5bfa847 Compare July 17, 2023 16:40
@ahoppen
Copy link
Member Author

ahoppen commented Jul 17, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jul 17, 2023

@swift-ci Please test Windows

Comment on lines -228 to +234
public var detached: Self {
var detached: Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

I very much dislike that we switch between visibility on the extension and visibility on each member here 😅. Ie. just below does the opposite.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let’s enable the swift-format rule that we don’t have an access level on an extension in a follow-up PR.

}

/// The textual byte length of this node exluding leading and trailing trivia.
@available(*, deprecated, message: "Use contentLength.utf8Length")
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the content name could work for the other places we're using trimmed right now? Or if this should be trimmedLength? I'm not sure content means "not including leading/trailing trivia" to me.

return totalLength.utf8Length
}

/// The textual byte length of this node exluding leading and trailing trivia.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// The textual byte length of this node exluding leading and trailing trivia.
/// The textual byte length of this node excluding leading and trailing trivia.

@ahoppen
Copy link
Member Author

ahoppen commented Jul 22, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jul 22, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 0c41fe6 into swiftlang:main Jul 23, 2023
@ahoppen ahoppen deleted the ahoppen/syntaxprotocol-api branch July 23, 2023 03:10
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