@@ -618,17 +618,10 @@ def _RefactoringToFixIt( refactoring ):
618
618
# the replacement text extracted from new_text
619
619
chunks .append ( responses .FixItChunk (
620
620
new_text [ new_start : new_end ],
621
- # FIXME: new_end must be equal to or after new_start, so we should make
622
- # OffsetToPosition take 2 offsets and return them rather than repeating
623
- # work
624
- responses .Range ( _OffsetToPosition ( old_start ,
625
- filename ,
626
- old_text ,
627
- newlines ),
628
- _OffsetToPosition ( old_end ,
629
- filename ,
630
- old_text ,
631
- newlines ) )
621
+ responses .Range ( * _OffsetToPosition ( ( old_start , old_end ),
622
+ filename ,
623
+ old_text ,
624
+ newlines ) )
632
625
) )
633
626
634
627
return responses .FixIt ( responses .Location ( 1 , 1 , 'none' ),
@@ -637,21 +630,26 @@ def _RefactoringToFixIt( refactoring ):
637
630
kind = responses .FixIt .Kind .REFACTOR )
638
631
639
632
640
- def _OffsetToPosition ( offset , filename , text , newlines ):
633
+ def _OffsetToPosition ( start_end , filename , text , newlines ):
641
634
"""Convert the 0-based codepoint offset |offset| to a position (line/col) in
642
635
|text|. |filename| is the full path of the file containing |text| and
643
636
|newlines| is a cache of the 0-based character offsets of all the \n
644
637
characters in |text| (plus one extra). Returns responses.Position."""
645
638
639
+ loc = ()
646
640
for index , newline in enumerate ( newlines ):
647
- if newline >= offset :
648
- start_of_line = newlines [ index - 1 ] + 1 if index > 0 else 0
649
- column = offset - start_of_line
650
- line_value = text [ start_of_line : newline ]
651
- return responses .Location ( index + 1 ,
652
- CodepointOffsetToByteOffset ( line_value ,
653
- column + 1 ),
654
- filename )
641
+ for offset in start_end [ len ( loc ): ]:
642
+ if newline >= offset :
643
+ start_of_line = newlines [ index - 1 ] + 1 if index > 0 else 0
644
+ column = offset - start_of_line
645
+ line_value = text [ start_of_line : newline ]
646
+ loc += ( responses .Location ( index + 1 ,
647
+ CodepointOffsetToByteOffset ( line_value ,
648
+ column + 1 ),
649
+ filename ), )
650
+ if len ( loc ) == 2 :
651
+ break
652
+ return loc
655
653
656
654
# Invalid position - it's outside of the text. Just return the last
657
655
# position in the text. This is an internal error.
0 commit comments