@@ -251,20 +251,55 @@ extension _SyntaxBase {
251
251
}
252
252
253
253
/// Sequence of `SyntaxClassifiedRange`s for this syntax node.
254
+ ///
255
+ /// The provided classified ranges are consecutive and cover the full source
256
+ /// text of the node. The ranges may also span multiple tokens, if multiple
257
+ /// consecutive tokens would have the same classification then a single classified
258
+ /// range is provided for all of them.
254
259
var classifications : SyntaxClassifications {
255
260
let fullRange = ByteSourceRange ( offset: 0 , length: byteSize)
256
261
return SyntaxClassifications ( self , in: fullRange)
257
262
}
258
263
259
264
/// Sequence of `SyntaxClassifiedRange`s contained in this syntax node within
260
265
/// a relative range.
266
+ ///
267
+ /// The provided classified ranges may extend beyond the provided `range`.
268
+ /// Active classifications (non-`none`) will extend the range to include the
269
+ /// full classified range (e.g. from the beginning of the comment block), while
270
+ /// `none` classified ranges will extend to the beginning or end of the token
271
+ /// that the `range` touches.
272
+ /// It is guaranteed that no classified range will be provided that doesn't
273
+ /// intersect the provided `range`.
274
+ ///
261
275
/// - Parameters:
262
276
/// - in: The relative byte range to pull `SyntaxClassifiedRange`s from.
263
277
/// - Returns: Sequence of `SyntaxClassifiedRange`s.
264
278
func classifications( in range: ByteSourceRange ) -> SyntaxClassifications {
265
279
return SyntaxClassifications ( self , in: range)
266
280
}
267
281
282
+ /// The `SyntaxClassifiedRange` for a relative byte offset.
283
+ /// - Parameters:
284
+ /// - at: The relative to the node byte offset.
285
+ /// - Returns: The `SyntaxClassifiedRange` for the offset or nil if the source text
286
+ /// at the given offset is unclassified.
287
+ func classification( at offset: Int ) -> SyntaxClassifiedRange ? {
288
+ let classifications = SyntaxClassifications ( self , in: ByteSourceRange ( offset: offset, length: 1 ) )
289
+ var iterator = classifications. makeIterator ( )
290
+ return iterator. next ( )
291
+ }
292
+
293
+ /// The `SyntaxClassifiedRange` for an absolute position.
294
+ /// - Parameters:
295
+ /// - at: The absolute position.
296
+ /// - Returns: The `SyntaxClassifiedRange` for the position or nil if the source text
297
+ /// at the given position is unclassified.
298
+ func classification( at position: AbsolutePosition ) -> SyntaxClassifiedRange ? {
299
+ let relativeOffset = position. utf8Offset - self . position. utf8Offset
300
+ return self . classification ( at: relativeOffset)
301
+ }
302
+
268
303
/// Returns a value representing the unique identity of the node.
269
304
var uniqueIdentifier : SyntaxIdentifier {
270
305
return data. nodeId
@@ -483,19 +518,51 @@ extension Syntax {
483
518
}
484
519
485
520
/// Sequence of `SyntaxClassifiedRange`s for this syntax node.
521
+ ///
522
+ /// The provided classification ranges are consecutive and cover the full source
523
+ /// text of the node. The ranges may also span multiple tokens, if multiple
524
+ /// consecutive tokens would have the same classification then a single classified
525
+ /// range is provided for all of them.
486
526
public var classifications : SyntaxClassifications {
487
527
return base. classifications
488
528
}
489
529
490
530
/// Sequence of `SyntaxClassifiedRange`s contained in this syntax node within
491
531
/// a relative range.
532
+ ///
533
+ /// The provided classified ranges may extend beyond the provided `range`.
534
+ /// Active classifications (non-`none`) will extend the range to include the
535
+ /// full classified range (e.g. from the beginning of the comment block), while
536
+ /// `none` classified ranges will extend to the beginning or end of the token
537
+ /// that the `range` touches.
538
+ /// It is guaranteed that no classified range will be provided that doesn't
539
+ /// intersect the provided `range`.
540
+ ///
492
541
/// - Parameters:
493
542
/// - in: The relative byte range to pull `SyntaxClassifiedRange`s from.
494
543
/// - Returns: Sequence of `SyntaxClassifiedRange`s.
495
544
public func classifications( in range: ByteSourceRange ) -> SyntaxClassifications {
496
545
return base. classifications ( in: range)
497
546
}
498
547
548
+ /// The `SyntaxClassifiedRange` for a relative byte offset.
549
+ /// - Parameters:
550
+ /// - at: The relative to the node byte offset.
551
+ /// - Returns: The `SyntaxClassifiedRange` for the offset or nil if the source text
552
+ /// at the given offset is unclassified.
553
+ public func classification( at offset: Int ) -> SyntaxClassifiedRange ? {
554
+ return base. classification ( at: offset)
555
+ }
556
+
557
+ /// The `SyntaxClassifiedRange` for an absolute position.
558
+ /// - Parameters:
559
+ /// - at: The absolute position.
560
+ /// - Returns: The `SyntaxClassifiedRange` for the position or nil if the source text
561
+ /// at the given position is unclassified.
562
+ public func classification( at position: AbsolutePosition ) -> SyntaxClassifiedRange ? {
563
+ return base. classification ( at: position)
564
+ }
565
+
499
566
/// Returns a value representing the unique identity of the node.
500
567
public var uniqueIdentifier : SyntaxIdentifier {
501
568
return base. uniqueIdentifier
0 commit comments