Skip to content

Commit

Permalink
Clean up BuildRequestDataForLocation
Browse files Browse the repository at this point in the history
- `badd` is unnecessary since we have `GetBufferNumberForFilename()`
- Instead of passing `location`, we can pass `file`, `line` and `column`
  separately.
  • Loading branch information
bstaletic committed Jun 19, 2024
1 parent ac002d5 commit 25ec3c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions python/ycm/client/base_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,15 @@ def BuildRequestData( buffer_number = None ):
}


def BuildRequestDataForLocation( location ):
file, line, column = location
if file not in vim.buffers:
vim.command( f'badd { file }' )
def BuildRequestDataForLocation( file : str, line : int, column : int ):
buffer_number = vimsupport.GetBufferNumberForFilename(
file,
create_buffer_if_needed = True )
try:
vim.eval( f'bufload( "{ file }" )' )
except vim.error as e:
if 'E325' not in str( e ):
raise

Check warning on line 260 in python/ycm/client/base_request.py

View check run for this annotation

Codecov / codecov/patch

python/ycm/client/base_request.py#L258-L260

Added lines #L258 - L260 were not covered by tests
buffer_number = vimsupport.GetBufferNumberForFilename( file )
buffer = vim.buffers[ buffer_number ]
file_data = vimsupport.GetUnsavedAndSpecifiedBufferData( buffer, file )
return {
Expand Down
2 changes: 1 addition & 1 deletion python/ycm/client/command_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__( self,

def Start( self ):
if self._location is not None:
self._request_data = BuildRequestDataForLocation( self._location )
self._request_data = BuildRequestDataForLocation( *self._location )
elif self._bufnr is not None:
self._request_data = BuildRequestData( self._bufnr )
else:
Expand Down

0 comments on commit 25ec3c9

Please sign in to comment.