-
Notifications
You must be signed in to change notification settings - Fork 439
Deprecate ByteSourceRange
in favor of Range<AbsolutePosition>
#2588
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
Deprecate ByteSourceRange
in favor of Range<AbsolutePosition>
#2588
Conversation
@swift-ci Please test |
…ent:)` This initializer was only introduced very recently since `IncrementalEdit` stores the replacement bytes instead of just the replacement length. We are now changing `IncrementalEdit` store the range it’s replacing as `Range<AbsolutePosition>` instead of `ByteSourceRange`. Companion of swiftlang/swift-syntax#2588
@swift-ci Please test |
@swift-ci Please test macOS |
/// at the given offset is unclassified. | ||
@available(*, deprecated, message: "Use classification(at: AbsolutePosition) instead") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deprecation feels a little odd since it actually has different behavior. Should we make that clear in the deprecation message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I changed it to maintain the same behavior it had before the PR and kept the deprecation message the same.
22435e4
to
0dfe3a4
Compare
0dfe3a4
to
e51cc5a
Compare
@swift-ci Please test |
/// Returns the range for the overlapping region between two ranges. | ||
/// | ||
/// If the intersection is empty, this returns `nil`. | ||
public func intersecting(_ other: Range<AbsolutePosition>) -> Range<AbsolutePosition>? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should use Range
methods like clamped(to:)
/ overlaps(_:)
. Is there a reason we can't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good suggestion. Added a commit that deprecates intersection
-style methods.
While being a little more verbose, this has a few advantages: - We only have a single type to represent ranges in SwiftSyntax instead of `Range<AbsolutePosition>` and `ByteSourceRange`, both of which we needed to use in sourcekit-lsp - Unifying the convenience functions on the two results in a single type that has all the convenience functions, instead of spreading them to two distinct sets - The use of `AbsolutePosition` and `SourceLength` makes type-system guarantees that these are UTF-8 byte positions / length, making it harder to accidentally add eg. UTF-16 lengths with UTF-8 lengths. rdar://125624626
e51cc5a
to
dca214e
Compare
@swift-ci Please test |
@swift-ci Please test |
Release Notes/600.md
Outdated
- Description: `SyntaxIdentifier.indexInTree` allows the retrieval of a `SyntaxIdentifier` that identifies the syntax node independent of the syntax tree. `SyntaxIdentifier.fromIndexInTree` allows the creation for a `SyntaxIdentifier` from a tree-agnostic `SyntaxIdentifier.IndexInTree` and the tree's root node. | ||
- Pull request: https://github.com/apple/swift-syntax/pull/2594 | ||
|
||
- `Range<AbsolutePosition>` | ||
- Description: `Range<AbsolutePosition>` gained a few convenience functions inspired from `ByteSourceRange`: `init(position:length:)`, `length`, `intersectsOrTouches`, `intersects`, `intersecting` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this for overlaps()
/clamped(to:)
style APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing. I forgot about the release notes
…utePosition>` We should use the native Range methods `clamped(to:)` and `overlaps` here. To match that naming scheme `intersectsOrTouches` has been renamed to `overlapsOrTouches`.
dca214e
to
b66915f
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test Windows |
While being a little more verbose, this has a few advantages:
Range<AbsolutePosition>
andByteSourceRange
, both of which we needed to use in sourcekit-lspAbsolutePosition
andSourceLength
makes type-system guarantees that these are UTF-8 byte positions / length, making it harder to accidentally add eg. UTF-16 lengths with UTF-8 lengths.rdar://125624626