Skip to content

Commit 2137056

Browse files
committed
Adjustment for the removal of IncrementalEdit(offset:length:replacement:)
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
1 parent d5e3dbd commit 2137056

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/SourceKitLSP/Swift/DocumentFormatting.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ private func edits(from original: DocumentSnapshot, to edited: String) -> [TextE
105105
let sequentialEdits = difference.map { change in
106106
switch change {
107107
case .insert(offset: let offset, element: let element, associatedWith: _):
108-
IncrementalEdit(offset: offset, length: 0, replacement: [element])
108+
let absolutePosition = AbsolutePosition(utf8Offset: offset)
109+
return IncrementalEdit(range: absolutePosition..<absolutePosition, replacement: [element])
109110
case .remove(offset: let offset, element: _, associatedWith: _):
110-
IncrementalEdit(offset: offset, length: 1, replacement: [])
111+
let absolutePosition = AbsolutePosition(utf8Offset: offset)
112+
return IncrementalEdit(range: absolutePosition..<absolutePosition.advanced(by: 1), replacement: [])
111113
}
112114
}
113115

0 commit comments

Comments
 (0)