@@ -360,9 +360,9 @@ func getStartPositionOfRange(r core.TextRange, sourceFile *ast.SourceFile, inclu
360
360
}
361
361
text := sourceFile .Text ()
362
362
pos := r .Pos ()
363
- // Bounds check: if position is beyond text length, it's likely from a different file
363
+ // Safety check: if position exceeds text length, it might be from a different file
364
364
if pos >= len (text ) {
365
- return pos // Return the original position without trying to skip trivia
365
+ return pos // Return the original position without attempting to skip trivia
366
366
}
367
367
return scanner .SkipTriviaEx (text , pos , & scanner.SkipTriviaOptions {StopAtComments : includeComments })
368
368
}
@@ -394,31 +394,19 @@ func getLinesBetweenRangeEndAndRangeStart(range1 core.TextRange, range2 core.Tex
394
394
}
395
395
396
396
func getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter (pos int , stopPos int , sourceFile * ast.SourceFile , includeComments bool ) int {
397
- text := sourceFile .Text ()
398
- if pos >= len (text ) {
399
- return 0 // Can't determine line differences for out-of-bounds positions
400
- }
401
- startPos := scanner .SkipTriviaEx (text , pos , & scanner.SkipTriviaOptions {StopAtComments : includeComments })
397
+ startPos := scanner .SkipTriviaEx (sourceFile .Text (), pos , & scanner.SkipTriviaOptions {StopAtComments : includeComments })
402
398
prevPos := getPreviousNonWhitespacePosition (startPos , stopPos , sourceFile )
403
399
return getLinesBetweenPositions (sourceFile , core .IfElse (prevPos >= 0 , prevPos , stopPos ), startPos )
404
400
}
405
401
406
402
func getLinesBetweenPositionAndNextNonWhitespaceCharacter (pos int , stopPos int , sourceFile * ast.SourceFile , includeComments bool ) int {
407
- text := sourceFile .Text ()
408
- if pos >= len (text ) {
409
- return 0 // Can't determine line differences for out-of-bounds positions
410
- }
411
- nextPos := scanner .SkipTriviaEx (text , pos , & scanner.SkipTriviaOptions {StopAtComments : includeComments })
403
+ nextPos := scanner .SkipTriviaEx (sourceFile .Text (), pos , & scanner.SkipTriviaOptions {StopAtComments : includeComments })
412
404
return getLinesBetweenPositions (sourceFile , pos , core .IfElse (stopPos < nextPos , stopPos , nextPos ))
413
405
}
414
406
415
407
func getPreviousNonWhitespacePosition (pos int , stopPos int , sourceFile * ast.SourceFile ) int {
416
- text := sourceFile .Text ()
417
408
for ; pos >= stopPos ; pos -- {
418
- if pos >= len (text ) {
419
- continue // Skip out-of-bounds positions
420
- }
421
- if ! stringutil .IsWhiteSpaceLike (rune (text [pos ])) {
409
+ if ! stringutil .IsWhiteSpaceLike (rune (sourceFile .Text ()[pos ])) {
422
410
return pos
423
411
}
424
412
}
0 commit comments