MCPcopy Index your code
hub / github.com/ycm-core/YouCompleteMe / ReplaceChunksInBuffer

Function ReplaceChunksInBuffer

python/ycm/vimsupport.py:1066–1091  ·  view source on GitHub ↗

Apply changes in |chunks| to the buffer-like object |buffer| and return the locations for that buffer.

( chunks, vim_buffer )

Source from the content-addressed store, hash-verified

1064
1065
1066def ReplaceChunksInBuffer( chunks, vim_buffer ):
1067 """Apply changes in |chunks| to the buffer-like object |buffer| and return the
1068 locations for that buffer."""
1069
1070 # We apply the chunks from the bottom to the top of the buffer so that we
1071 # don't need to adjust the position of the remaining chunks due to text
1072 # changes. This assumes that chunks are not overlapping. However, we still
1073 # allow multiple chunks to share the same starting position (because of the
1074 # language server protocol specs). These chunks must be applied in their order
1075 # of appareance. Since Python sorting is stable, if we sort the whole list in
1076 # reverse order of location, these chunks will be reversed. Therefore, we
1077 # need to fully reverse the list then sort it on the starting position in
1078 # reverse order.
1079 chunks.reverse()
1080 chunks.sort( key = lambda chunk: (
1081 chunk[ 'range' ][ 'start' ][ 'line_num' ],
1082 chunk[ 'range' ][ 'start' ][ 'column_num' ]
1083 ), reverse = True )
1084
1085 # However, we still want to display the locations from the top of the buffer
1086 # to its bottom.
1087 return reversed( [ ReplaceChunk( chunk[ 'range' ][ 'start' ],
1088 chunk[ 'range' ][ 'end' ],
1089 chunk[ 'replacement_text' ],
1090 vim_buffer )
1091 for chunk in chunks ] )
1092
1093
1094def SplitLines( contents ):

Callers 1

ReplaceChunksFunction · 0.85

Calls 1

ReplaceChunkFunction · 0.85

Tested by

no test coverage detected