@@ -162,7 +162,7 @@ struct IncrementalParseLookup {
162
162
163
163
// Fast path check: if parser is past all the edits then any matching node
164
164
// can be re-used.
165
- if !edits. edits. isEmpty && edits. edits. last!. range. endOffset < node. position. utf8Offset {
165
+ if !edits. edits. isEmpty && edits. edits. last!. range. upperBound . utf8Offset < node. position. utf8Offset {
166
166
return true
167
167
}
168
168
@@ -172,15 +172,15 @@ struct IncrementalParseLookup {
172
172
return false
173
173
}
174
174
175
- let nodeAffectRange = ByteSourceRange (
176
- offset : node . position . utf8Offset ,
177
- length : nodeAffectRangeLength
178
- )
175
+ let nodeAffectRange =
176
+ AbsolutePosition (
177
+ utf8Offset : node . position . utf8Offset
178
+ ) ..< AbsolutePosition ( utf8Offset : node . position . utf8Offset + nodeAffectRangeLength )
179
179
180
180
for edit in edits. edits {
181
181
// Check if this node or the trivia of the next node has been edited. If
182
182
// it has, we cannot reuse it.
183
- if edit. range. offset > nodeAffectRange. endOffset {
183
+ if edit. range. lowerBound . utf8Offset > nodeAffectRange. upperBound . utf8Offset {
184
184
// Remaining edits don't affect the node. (Edits are sorted)
185
185
break
186
186
}
@@ -195,11 +195,11 @@ struct IncrementalParseLookup {
195
195
fileprivate func translateToPreEditOffset( _ postEditOffset: Int ) -> Int ? {
196
196
var offset = postEditOffset
197
197
for edit in edits. edits {
198
- if edit. range. offset > offset {
198
+ if edit. range. lowerBound . utf8Offset > offset {
199
199
// Remaining edits doesn't affect the position. (Edits are sorted)
200
200
break
201
201
}
202
- if edit. range. offset + edit. replacementLength > offset {
202
+ if edit. range. lowerBound . utf8Offset + edit. replacementLength > offset {
203
203
// This is a position inserted by the edit, and thus doesn't exist in
204
204
// the pre-edit version of the file.
205
205
return nil
@@ -303,11 +303,11 @@ public struct ConcurrentEdits: Sendable {
303
303
304
304
/// The raw concurrent edits. Are guaranteed to satisfy the requirements
305
305
/// stated above.
306
- public let edits : [ IncrementalEdit ]
306
+ public let edits : [ SourceEdit ]
307
307
308
308
/// Initialize this struct from edits that are already in a concurrent form
309
309
/// and are guaranteed to satisfy the requirements posed above.
310
- public init ( concurrent: [ IncrementalEdit ] ) throws {
310
+ public init ( concurrent: [ SourceEdit ] ) throws {
311
311
if !Self. isValidConcurrentEditArray ( concurrent) {
312
312
throw ConcurrentEditsError . editsNotConcurrent
313
313
}
@@ -323,7 +323,7 @@ public struct ConcurrentEdits: Sendable {
323
323
/// - insert 'z' at offset 2
324
324
/// to '012345' results in 'xyz012345'.
325
325
326
- public init ( fromSequential sequentialEdits: [ IncrementalEdit ] ) {
326
+ public init ( fromSequential sequentialEdits: [ SourceEdit ] ) {
327
327
do {
328
328
try self . init ( concurrent: Self . translateSequentialEditsToConcurrentEdits ( sequentialEdits) )
329
329
} catch {
@@ -336,7 +336,7 @@ public struct ConcurrentEdits: Sendable {
336
336
/// Construct a concurrent edits struct from a single edit. For a single edit,
337
337
/// there is no differentiation between being it being applied concurrently
338
338
/// or sequentially.
339
- public init ( _ single: IncrementalEdit ) {
339
+ public init ( _ single: SourceEdit ) {
340
340
do {
341
341
try self . init ( concurrent: [ single] )
342
342
} catch {
@@ -345,9 +345,9 @@ public struct ConcurrentEdits: Sendable {
345
345
}
346
346
347
347
private static func translateSequentialEditsToConcurrentEdits(
348
- _ edits: [ IncrementalEdit ]
349
- ) -> [ IncrementalEdit ] {
350
- var concurrentEdits : [ IncrementalEdit ] = [ ]
348
+ _ edits: [ SourceEdit ]
349
+ ) -> [ SourceEdit ] {
350
+ var concurrentEdits : [ SourceEdit ] = [ ]
351
351
for editToAdd in edits {
352
352
var editToAdd = editToAdd
353
353
var editIndicesMergedWithNewEdit : [ Int ] = [ ]
@@ -360,14 +360,14 @@ public struct ConcurrentEdits: Sendable {
360
360
existingEdit. replacement. prefix ( max ( 0 , editToAdd. offset - existingEdit. replacementRange. offset) )
361
361
+ editToAdd. replacement
362
362
+ existingEdit. replacement. suffix ( max ( 0 , existingEdit. replacementRange. endOffset - editToAdd. endOffset) )
363
- editToAdd = IncrementalEdit (
363
+ editToAdd = SourceEdit (
364
364
offset: Swift . min ( existingEdit. offset, editToAdd. offset) ,
365
365
length: existingEdit. length + editToAdd. length - intersectionLength,
366
366
replacement: replacement
367
367
)
368
368
editIndicesMergedWithNewEdit. append ( index)
369
- } else if existingEdit. offset < editToAdd. endOffset {
370
- editToAdd = IncrementalEdit (
369
+ } else if existingEdit. range . lowerBound . utf8Offset < editToAdd. range . upperBound . utf8Offset {
370
+ editToAdd = SourceEdit (
371
371
offset: editToAdd. offset - existingEdit. replacementLength + existingEdit. length,
372
372
length: editToAdd. length,
373
373
replacement: editToAdd. replacement
@@ -380,15 +380,15 @@ public struct ConcurrentEdits: Sendable {
380
380
}
381
381
let insertPos =
382
382
concurrentEdits. firstIndex ( where: { edit in
383
- editToAdd. endOffset <= edit. offset
383
+ editToAdd. range . upperBound . utf8Offset <= edit. range . lowerBound . utf8Offset
384
384
} ) ?? concurrentEdits. count
385
385
concurrentEdits. insert ( editToAdd, at: insertPos)
386
386
precondition ( ConcurrentEdits . isValidConcurrentEditArray ( concurrentEdits) )
387
387
}
388
388
return concurrentEdits
389
389
}
390
390
391
- private static func isValidConcurrentEditArray( _ edits: [ IncrementalEdit ] ) -> Bool {
391
+ private static func isValidConcurrentEditArray( _ edits: [ SourceEdit ] ) -> Bool {
392
392
// Not quite sure if we should disallow creating an `IncrementalParseTransition`
393
393
// object without edits but there doesn't seem to be much benefit if we do,
394
394
// and there are 'lit' tests that want to test incremental re-parsing without edits.
@@ -397,7 +397,7 @@ public struct ConcurrentEdits: Sendable {
397
397
for i in 1 ..< edits. count {
398
398
let prevEdit = edits [ i - 1 ]
399
399
let curEdit = edits [ i]
400
- if curEdit. range. offset < prevEdit. range. endOffset {
400
+ if curEdit. range. lowerBound . utf8Offset < prevEdit. range. upperBound . utf8Offset {
401
401
return false
402
402
}
403
403
if curEdit. intersectsRange ( prevEdit. range) {
@@ -408,7 +408,7 @@ public struct ConcurrentEdits: Sendable {
408
408
}
409
409
410
410
/// **Public for testing purposes only**
411
- public static func _isValidConcurrentEditArray( _ edits: [ IncrementalEdit ] ) -> Bool {
411
+ public static func _isValidConcurrentEditArray( _ edits: [ SourceEdit ] ) -> Bool {
412
412
return isValidConcurrentEditArray ( edits)
413
413
}
414
414
}
0 commit comments