Skip to content

Commit 9e6b32b

Browse files
Maksim V. Nikulinmergify[bot]
authored andcommitted
Tidy up supposed FIXME
1 parent 7a0592c commit 9e6b32b

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

ycmd/completers/python/python_completer.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -618,17 +618,10 @@ def _RefactoringToFixIt( refactoring ):
618618
# the replacement text extracted from new_text
619619
chunks.append( responses.FixItChunk(
620620
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 ) )
632625
) )
633626

634627
return responses.FixIt( responses.Location( 1, 1, 'none' ),
@@ -637,21 +630,26 @@ def _RefactoringToFixIt( refactoring ):
637630
kind = responses.FixIt.Kind.REFACTOR )
638631

639632

640-
def _OffsetToPosition( offset, filename, text, newlines ):
633+
def _OffsetToPosition( start_end, filename, text, newlines ):
641634
"""Convert the 0-based codepoint offset |offset| to a position (line/col) in
642635
|text|. |filename| is the full path of the file containing |text| and
643636
|newlines| is a cache of the 0-based character offsets of all the \n
644637
characters in |text| (plus one extra). Returns responses.Position."""
645638

639+
loc = ()
646640
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
655653

656654
# Invalid position - it's outside of the text. Just return the last
657655
# position in the text. This is an internal error.

0 commit comments

Comments
 (0)