Skip to content

Commit f83bc36

Browse files
committed
Make all subcommands async
1 parent 4f1dcf4 commit f83bc36

File tree

4 files changed

+74
-82
lines changed

4 files changed

+74
-82
lines changed

Diff for: autoload/youcompleteme.vim

+33-10
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,18 @@ function! s:PollCommands( timer_id ) abort
15071507
let poll_again = 1
15081508
continue
15091509
else
1510-
let result = py3eval( 'ycm_state.GetCommandRequest( '
1511-
\ . 'int( vim.eval( "request_id" ) ) ).'
1512-
\ . request.response_func
1513-
\ . '()' )
1510+
if len( request.response_func_args ) == 0
1511+
let result = py3eval( 'ycm_state.GetCommandRequest( '
1512+
\ . 'int( vim.eval( "request_id" ) ) ).'
1513+
\ . request.response_func
1514+
\ . '()' )
1515+
else
1516+
let result = py3eval( 'ycm_state.GetCommandRequest( '
1517+
\ . 'int( vim.eval( "request_id" ) ) ).'
1518+
\ . request.response_func
1519+
\ . '(' . request.response_func_args . ')' )
1520+
let request.response_func_args = ''
1521+
endif
15141522
endif
15151523

15161524
" This request is done
@@ -1526,13 +1534,28 @@ function! s:PollCommands( timer_id ) abort
15261534
endfunction
15271535

15281536

1537+
function! s:EmptyCallback( result ) abort
1538+
endfunction
1539+
1540+
15291541
function! s:CompleterCommand( mods, count, line1, line2, ... )
1530-
py3 ycm_state.SendCommandRequest(
1531-
\ vim.eval( 'a:000' ),
1532-
\ vim.eval( 'a:mods' ),
1533-
\ vimsupport.GetBoolValue( 'a:count != -1' ),
1534-
\ vimsupport.GetIntValue( 'a:line1' ),
1535-
\ vimsupport.GetIntValue( 'a:line2' ) )
1542+
let request_id = py3eval( 'ycm_state.SendCommandRequestAsync(' .
1543+
\ ' vim.eval( "a:000" ),' .
1544+
\ ' vimsupport.GetBoolValue( "a:count != -1" ),' .
1545+
\ ' vimsupport.GetIntValue( "a:line1" ),' .
1546+
\ ' vimsupport.GetIntValue( "a:line2" ),' .
1547+
\ ' False )' )
1548+
let s:pollers.command.requests[ request_id ] = {
1549+
\ 'response_func': 'RunPostCommandActionsIfNeeded',
1550+
\ 'response_func_args':
1551+
\ '"' . a:mods . '","' . g:ycm_goto_buffer_command . '"',
1552+
\ 'callback': function( 's:EmptyCallback' )
1553+
\ }
1554+
if s:pollers.command.id == -1
1555+
let s:pollers.command.id =
1556+
\ timer_start( s:pollers.command.wait_milliseconds,
1557+
\ function( 's:PollCommands' ) )
1558+
endif
15361559
endfunction
15371560

15381561

Diff for: python/ycm/client/command_request.py

-12
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,6 @@ def SendCommandRequestAsync( arguments, extra_data = None, silent = True ):
215215
return request
216216

217217

218-
def SendCommandRequest( arguments,
219-
modifiers,
220-
buffer_command = DEFAULT_BUFFER_COMMAND,
221-
extra_data = None ):
222-
request = SendCommandRequestAsync( arguments,
223-
extra_data = extra_data,
224-
silent = False )
225-
# Block here to get the response
226-
request.RunPostCommandActionsIfNeeded( modifiers, buffer_command )
227-
return request.Response()
228-
229-
230218
def GetCommandResponse( arguments, extra_data = None ):
231219
request = SendCommandRequestAsync( arguments,
232220
extra_data = extra_data,

Diff for: python/ycm/tests/command_test.py

+29-34
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@
2727

2828
class CommandTest( TestCase ):
2929
@YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'tempname()' ] } )
30-
def test_SendCommandRequest_ExtraConfVimData_Works( self, ycm ):
30+
def test_SendCommandRequestAsync_ExtraConfVimData_Works( self, ycm ):
3131
current_buffer = VimBuffer( 'buffer' )
3232
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
33-
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
34-
ycm.SendCommandRequest( [ 'GoTo' ], 'aboveleft', False, 1, 1 )
33+
with patch( 'ycm.youcompleteme.SendCommandRequestAsync' ) as send_request:
34+
ycm.SendCommandRequestAsync( [ 'GoTo' ], False, 1, 1 )
3535
assert_that(
36-
# Positional arguments passed to SendCommandRequest.
36+
# Positional arguments passed to SendCommandRequestAsync.
3737
send_request.call_args[ 0 ],
3838
contains_exactly(
3939
contains_exactly( 'GoTo' ),
40-
'aboveleft',
41-
'same-buffer',
4240
has_entries( {
4341
'options': has_entries( {
4442
'tab_size': 2,
@@ -47,46 +45,44 @@ def test_SendCommandRequest_ExtraConfVimData_Works( self, ycm ):
4745
'extra_conf_data': has_entries( {
4846
'tempname()': '_TEMP_FILE_'
4947
} ),
50-
} )
48+
} ),
49+
True
5150
)
5251
)
5352

5453

5554
@YouCompleteMeInstance( {
5655
'g:ycm_extra_conf_vim_data': [ 'undefined_value' ] } )
57-
def test_SendCommandRequest_ExtraConfData_UndefinedValue( self, ycm ):
56+
def test_SendCommandRequestAsync_ExtraConfData_UndefinedValue( self, ycm ):
5857
current_buffer = VimBuffer( 'buffer' )
5958
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
60-
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
61-
ycm.SendCommandRequest( [ 'GoTo' ], 'belowright', False, 1, 1 )
59+
with patch( 'ycm.youcompleteme.SendCommandRequestAsync' ) as send_request:
60+
ycm.SendCommandRequestAsync( [ 'GoTo' ], False, 1, 1 )
6261
assert_that(
63-
# Positional arguments passed to SendCommandRequest.
62+
# Positional arguments passed to SendCommandRequestAsync.
6463
send_request.call_args[ 0 ],
6564
contains_exactly(
6665
contains_exactly( 'GoTo' ),
67-
'belowright',
68-
'same-buffer',
6966
has_entries( {
7067
'options': has_entries( {
7168
'tab_size': 2,
7269
'insert_spaces': True,
7370
} )
74-
} )
71+
} ),
72+
True
7573
)
7674
)
7775

7876

7977
@YouCompleteMeInstance()
80-
def test_SendCommandRequest_BuildRange_NoVisualMarks( self, ycm, *args ):
78+
def test_SendCommandRequestAsync_BuildRange_NoVisualMarks( self, ycm, *args ):
8179
current_buffer = VimBuffer( 'buffer', contents = [ 'first line',
8280
'second line' ] )
8381
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
84-
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
85-
ycm.SendCommandRequest( [ 'GoTo' ], '', True, 1, 2 )
82+
with patch( 'ycm.youcompleteme.SendCommandRequestAsync' ) as send_request:
83+
ycm.SendCommandRequestAsync( [ 'GoTo' ], True, 1, 2 )
8684
send_request.assert_called_once_with(
8785
[ 'GoTo' ],
88-
'',
89-
'same-buffer',
9086
{
9187
'options': {
9288
'tab_size': 2,
@@ -102,24 +98,23 @@ def test_SendCommandRequest_BuildRange_NoVisualMarks( self, ycm, *args ):
10298
'column_num': 12
10399
}
104100
}
105-
}
101+
},
102+
True
106103
)
107104

108105

109106
@YouCompleteMeInstance()
110-
def test_SendCommandRequest_BuildRange_VisualMarks( self, ycm, *args ):
107+
def test_SendCommandRequestAsync_BuildRange_VisualMarks( self, ycm, *args ):
111108
current_buffer = VimBuffer( 'buffer',
112109
contents = [ 'first line',
113110
'second line' ],
114111
visual_start = [ 1, 4 ],
115112
visual_end = [ 2, 8 ] )
116113
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
117-
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
118-
ycm.SendCommandRequest( [ 'GoTo' ], 'tab', True, 1, 2 )
114+
with patch( 'ycm.youcompleteme.SendCommandRequestAsync' ) as send_request:
115+
ycm.SendCommandRequestAsync( [ 'GoTo' ], True, 1, 2 )
119116
send_request.assert_called_once_with(
120117
[ 'GoTo' ],
121-
'tab',
122-
'same-buffer',
123118
{
124119
'options': {
125120
'tab_size': 2,
@@ -135,31 +130,31 @@ def test_SendCommandRequest_BuildRange_VisualMarks( self, ycm, *args ):
135130
'column_num': 9
136131
}
137132
}
138-
}
133+
},
134+
True
139135
)
140136

141137

142138
@YouCompleteMeInstance()
143-
def test_SendCommandRequest_IgnoreFileTypeOption( self, ycm, *args ):
139+
def test_SendCommandRequestAsync_IgnoreFileTypeOption( self, ycm, *args ):
144140
current_buffer = VimBuffer( 'buffer' )
145141
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
146142
expected_args = (
147143
[ 'GoTo' ],
148-
'',
149-
'same-buffer',
150144
{
151145
'completer_target': 'python',
152146
'options': {
153147
'tab_size': 2,
154148
'insert_spaces': True
155149
},
156-
}
150+
},
151+
False
157152
)
158153

159-
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
160-
ycm.SendCommandRequest( [ 'ft=python', 'GoTo' ], '', False, 1, 1 )
154+
with patch( 'ycm.youcompleteme.SendCommandRequestAsync' ) as send_request:
155+
ycm.SendCommandRequestAsync( [ 'ft=python', 'GoTo' ], False, 1, 1, False )
161156
send_request.assert_called_once_with( *expected_args )
162157

163-
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
164-
ycm.SendCommandRequest( [ 'GoTo', 'ft=python' ], '', False, 1, 1 )
158+
with patch( 'ycm.youcompleteme.SendCommandRequestAsync' ) as send_request:
159+
ycm.SendCommandRequestAsync( [ 'GoTo', 'ft=python' ], False, 1, 1, False )
165160
send_request.assert_called_once_with( *expected_args )

Diff for: python/ycm/youcompleteme.py

+12-26
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
from ycm.client.ycmd_keepalive import YcmdKeepalive
3333
from ycm.client.base_request import BaseRequest, BuildRequestData
3434
from ycm.client.completer_available_request import SendCompleterAvailableRequest
35-
from ycm.client.command_request import ( SendCommandRequest,
36-
SendCommandRequestAsync,
35+
from ycm.client.command_request import ( SendCommandRequestAsync,
3736
GetCommandResponse )
3837
from ycm.client.completion_request import CompletionRequest
3938
from ycm.client.resolve_completion_request import ResolveCompletionItem
@@ -403,25 +402,6 @@ def _GetCommandRequestArguments( self,
403402
return final_arguments, extra_data
404403

405404

406-
407-
def SendCommandRequest( self,
408-
arguments,
409-
modifiers,
410-
has_range,
411-
start_line,
412-
end_line ):
413-
final_arguments, extra_data = self._GetCommandRequestArguments(
414-
arguments,
415-
has_range,
416-
start_line,
417-
end_line )
418-
return SendCommandRequest(
419-
final_arguments,
420-
modifiers,
421-
self._user_options[ 'goto_buffer_command' ],
422-
extra_data )
423-
424-
425405
def GetCommandResponse( self, arguments ):
426406
final_arguments, extra_data = self._GetCommandRequestArguments(
427407
arguments,
@@ -431,18 +411,24 @@ def GetCommandResponse( self, arguments ):
431411
return GetCommandResponse( final_arguments, extra_data )
432412

433413

434-
def SendCommandRequestAsync( self, arguments ):
414+
def SendCommandRequestAsync( self,
415+
arguments,
416+
has_range = False,
417+
start_line = 0,
418+
end_line = 0,
419+
silent = True ):
435420
final_arguments, extra_data = self._GetCommandRequestArguments(
436421
arguments,
437-
False,
438-
0,
439-
0 )
422+
has_range,
423+
start_line,
424+
end_line )
440425

441426
request_id = self._next_command_request_id
442427
self._next_command_request_id += 1
443428
self._command_requests[ request_id ] = SendCommandRequestAsync(
444429
final_arguments,
445-
extra_data )
430+
extra_data,
431+
silent )
446432
return request_id
447433

448434

0 commit comments

Comments
 (0)