MCPcopy
hub / github.com/ycm-core/YouCompleteMe / RangeVisibleInBuffer

Function RangeVisibleInBuffer

python/ycm/vimsupport.py:192–241  ·  view source on GitHub ↗
( bufnr, grow_factor=0.5 )

Source from the content-addressed store, hash-verified

190# tab page for the supplied buffer number. By default this range is then
191# extended by half of the resulting range size
192def RangeVisibleInBuffer( bufnr, grow_factor=0.5 ):
193 windows = [ w for w in vim.eval( f'win_findbuf( { bufnr } )' )
194 if GetIntValue( vim.eval( f'win_id2tabwin( { w } )[ 0 ]' ) ) ==
195 vim.current.tabpage.number ]
196
197 class Location:
198 line: int = None
199 col: int = None
200
201 class Range:
202 start: Location = Location()
203 end: Location = Location()
204
205 try:
206 buffer = vim.buffers[ bufnr ]
207 except KeyError:
208 return None
209
210 if not windows:
211 return None
212
213 r = Range()
214 # Note, for this we ignore horizontal scrolling
215 for winid in windows:
216 win_info = vim.eval( f'getwininfo( { winid } )[ 0 ]' )
217 if r.start.line is None or r.start.line > int( win_info[ 'topline' ] ):
218 r.start.line = int( win_info[ 'topline' ] )
219 if r.end.line is None or r.end.line < int( win_info[ 'botline' ] ):
220 r.end.line = int( win_info[ 'botline' ] )
221
222 # Extend the range by 1 factor, and calculate the columns
223 num_lines = r.end.line - r.start.line + 1
224 r.start.line = max( r.start.line - int( num_lines * grow_factor ), 1 )
225 r.start.col = 1
226 r.end.line = min( r.end.line + int( num_lines * grow_factor ), len( buffer ) )
227 r.end.col = len( buffer[ r.end.line - 1 ] )
228
229 filepath = GetBufferFilepath( buffer )
230 return {
231 'start': {
232 'line_num': r.start.line,
233 'column_num': r.start.col,
234 'filepath': filepath,
235 },
236 'end': {
237 'line_num': r.end.line,
238 'column_num': r.end.col,
239 'filepath': filepath,
240 }
241 }
242
243
244def VisibleRangeOfBufferOverlaps( bufnr, expanded_range ):

Callers 1

Calls 3

GetIntValueFunction · 0.85
RangeClass · 0.85
GetBufferFilepathFunction · 0.85

Tested by

no test coverage detected