Ignore ft= argument from YcmCompleter command

Only the "ycm:ident" value of the ft= argument in the YcmCompleter
command is working. This value forces the use of the identifier
completer which serve no purpose because this completer doesn't define
commands. Ignore completely the ft= argument and move the logic to the
Python layer.
This commit is contained in:
micbou 2018-09-27 02:33:11 +02:00
parent e37923a752
commit bdc3a66488
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
6 changed files with 53 additions and 55 deletions

View File

@ -1507,18 +1507,13 @@ This command gives access to a number of additional [IDE-like
features](#quick-feature-summary) in YCM, for things like semantic GoTo, type features](#quick-feature-summary) in YCM, for things like semantic GoTo, type
information, FixIt and refactoring. information, FixIt and refactoring.
Technically the command invokes completer-specific commands. If the first This command accepts a range that can either be specified through a selection in
argument is of the form `ft=...` the completer for that file type will be used one of Vim's visual modes (see `:h visual-use`) or on the command line. For
(for example `ft=cpp`), else the native completer of the current buffer will be instance, `:2,5YcmCompleter` will apply the command from line 2 to line 5. This
used. is useful for [the `Format` subcommand](#the-format-subcommand).
This command also accepts a range that can either be specified through a Call `YcmCompleter` without further arguments for a list of the commands you can
selection in one of Vim's visual modes (see `:h visual-use`) or on the command call for the current completer.
line. For instance, `:2,5YcmCompleter` will apply the command from line 2 to
line 5. This is useful for [the `Format` subcommand](#the-format-subcommand).
Call `YcmCompleter` without further arguments for a list of the
commands you can call for the current completer.
See the [file type feature summary](#quick-feature-summary) for an overview of See the [file type feature summary](#quick-feature-summary) for an overview of
the features available for each file type. See the _YcmCompleter subcommands_ the features available for each file type. See the _YcmCompleter subcommands_

View File

@ -900,26 +900,8 @@ endfunction
function! s:CompleterCommand( mods, count, line1, line2, ... ) function! s:CompleterCommand( mods, count, line1, line2, ... )
" CompleterCommand will call the OnUserCommand function of a completer. If
" the first arguments is of the form "ft=..." it can be used to specify the
" completer to use (for example "ft=cpp"). Else the native filetype completer
" of the current buffer is used. If no native filetype completer is found and
" no completer was specified this throws an error. You can use "ft=ycm:ident"
" to select the identifier completer. The remaining arguments will be passed
" to the completer.
let arguments = copy(a:000)
let completer = ''
if a:0 > 0 && strpart(a:1, 0, 3) == 'ft='
if a:1 == 'ft=ycm:ident'
let completer = 'identifier'
endif
let arguments = arguments[1:]
endif
exec s:python_command "ycm_state.SendCommandRequest(" . exec s:python_command "ycm_state.SendCommandRequest(" .
\ "vim.eval( 'l:arguments' )," . \ "vim.eval( 'a:000' )," .
\ "vim.eval( 'l:completer' )," .
\ "vim.eval( 'a:mods' )," . \ "vim.eval( 'a:mods' )," .
\ "vimsupport.GetBoolValue( 'a:count != -1' )," . \ "vimsupport.GetBoolValue( 'a:count != -1' )," .
\ "vimsupport.GetIntValue( 'a:line1' )," . \ "vimsupport.GetIntValue( 'a:line1' )," .

View File

@ -1746,15 +1746,10 @@ The *:YcmCompleter* command
This command gives access to a number of additional IDE-like features in YCM, This command gives access to a number of additional IDE-like features in YCM,
for things like semantic GoTo, type information, FixIt and refactoring. for things like semantic GoTo, type information, FixIt and refactoring.
Technically the command invokes completer-specific commands. If the first This command accepts a range that can either be specified through a selection
argument is of the form 'ft=...' the completer for that file type will be used in one of Vim's visual modes (see ':h visual-use') or on the command line. For
(for example 'ft=cpp'), else the native completer of the current buffer will be instance, ':2,5YcmCompleter' will apply the command from line 2 to line 5. This
used. is useful for the |Format| subcommand.
This command also accepts a range that can either be specified through a
selection in one of Vim's visual modes (see ':h visual-use') or on the command
line. For instance, ':2,5YcmCompleter' will apply the command from line 2 to
line 5. This is useful for the |Format| subcommand.
Call 'YcmCompleter' without further arguments for a list of the commands you Call 'YcmCompleter' without further arguments for a list of the commands you
can call for the current completer. can call for the current completer.

View File

@ -34,12 +34,10 @@ def _EnsureBackwardsCompatibility( arguments ):
class CommandRequest( BaseRequest ): class CommandRequest( BaseRequest ):
def __init__( self, arguments, completer_target = None, extra_data = None ): def __init__( self, arguments, extra_data = None ):
super( CommandRequest, self ).__init__() super( CommandRequest, self ).__init__()
self._arguments = _EnsureBackwardsCompatibility( arguments ) self._arguments = _EnsureBackwardsCompatibility( arguments )
self._command = arguments and arguments[ 0 ] self._command = arguments and arguments[ 0 ]
self._completer_target = ( completer_target if completer_target
else 'filetype_default' )
self._extra_data = extra_data self._extra_data = extra_data
self._response = None self._response = None
@ -49,7 +47,6 @@ class CommandRequest( BaseRequest ):
if self._extra_data: if self._extra_data:
request_data.update( self._extra_data ) request_data.update( self._extra_data )
request_data.update( { request_data.update( {
'completer_target': self._completer_target,
'command_arguments': self._arguments 'command_arguments': self._arguments
} ) } )
self._response = self.PostDataToHandler( request_data, self._response = self.PostDataToHandler( request_data,
@ -132,8 +129,8 @@ class CommandRequest( BaseRequest ):
vimsupport.WriteToPreviewWindow( self._response[ 'detailed_info' ] ) vimsupport.WriteToPreviewWindow( self._response[ 'detailed_info' ] )
def SendCommandRequest( arguments, completer, modifiers, extra_data = None ): def SendCommandRequest( arguments, modifiers, extra_data = None ):
request = CommandRequest( arguments, completer, extra_data ) request = CommandRequest( arguments, extra_data )
# This is a blocking call. # This is a blocking call.
request.Start() request.Start()
request.RunPostCommandActionsIfNeeded( modifiers ) request.RunPostCommandActionsIfNeeded( modifiers )

View File

@ -36,13 +36,12 @@ def SendCommandRequest_ExtraConfVimData_Works_test( ycm ):
current_buffer = VimBuffer( 'buffer' ) current_buffer = VimBuffer( 'buffer' )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python', 'aboveleft', False, 1, 1 ) ycm.SendCommandRequest( [ 'GoTo' ], 'aboveleft', False, 1, 1 )
assert_that( assert_that(
# Positional arguments passed to SendCommandRequest. # Positional arguments passed to SendCommandRequest.
send_request.call_args[ 0 ], send_request.call_args[ 0 ],
contains( contains(
contains( 'GoTo' ), contains( 'GoTo' ),
'python',
'aboveleft', 'aboveleft',
has_entries( { has_entries( {
'options': has_entries( { 'options': has_entries( {
@ -62,13 +61,12 @@ def SendCommandRequest_ExtraConfData_UndefinedValue_test( ycm ):
current_buffer = VimBuffer( 'buffer' ) current_buffer = VimBuffer( 'buffer' )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python', 'belowright', False, 1, 1 ) ycm.SendCommandRequest( [ 'GoTo' ], 'belowright', False, 1, 1 )
assert_that( assert_that(
# Positional arguments passed to SendCommandRequest. # Positional arguments passed to SendCommandRequest.
send_request.call_args[ 0 ], send_request.call_args[ 0 ],
contains( contains(
contains( 'GoTo' ), contains( 'GoTo' ),
'python',
'belowright', 'belowright',
has_entries( { has_entries( {
'options': has_entries( { 'options': has_entries( {
@ -86,10 +84,9 @@ def SendCommandRequest_BuildRange_NoVisualMarks_test( ycm, *args ):
'second line' ] ) 'second line' ] )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python', '', True, 1, 2 ) ycm.SendCommandRequest( [ 'GoTo' ], '', True, 1, 2 )
send_request.assert_called_once_with( send_request.assert_called_once_with(
[ 'GoTo' ], [ 'GoTo' ],
'python',
'', '',
{ {
'options': { 'options': {
@ -119,10 +116,9 @@ def SendCommandRequest_BuildRange_VisualMarks_test( ycm, *args ):
visual_end = [ 2, 8 ] ) visual_end = [ 2, 8 ] )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo' ], 'python', 'tab', True, 1, 2 ) ycm.SendCommandRequest( [ 'GoTo' ], 'tab', True, 1, 2 )
send_request.assert_called_once_with( send_request.assert_called_once_with(
[ 'GoTo' ], [ 'GoTo' ],
'python',
'tab', 'tab',
{ {
'options': { 'options': {
@ -141,3 +137,27 @@ def SendCommandRequest_BuildRange_VisualMarks_test( ycm, *args ):
} }
} }
) )
@YouCompleteMeInstance()
def SendCommandRequest_IgnoreFileTypeOption_test( ycm, *args ):
current_buffer = VimBuffer( 'buffer' )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
expected_args = (
[ 'GoTo' ],
'',
{
'options': {
'tab_size': 2,
'insert_spaces': True
},
}
)
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'ft=ycm:ident', 'GoTo' ], '', False, 1, 1 )
send_request.assert_called_once_with( *expected_args )
with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
ycm.SendCommandRequest( [ 'GoTo', 'ft=python' ], '', False, 1, 1 )
send_request.assert_called_once_with( *expected_args )

View File

@ -321,11 +321,19 @@ class YouCompleteMe( object ):
def SendCommandRequest( self, def SendCommandRequest( self,
arguments, arguments,
completer,
modifiers, modifiers,
has_range, has_range,
start_line, start_line,
end_line ): end_line ):
final_arguments = []
for argument in arguments:
# The ft= option which specifies the completer when running a command is
# ignored because it has not been working for a long time. The option is
# still parsed to not break users that rely on it.
if argument.startswith( 'ft=' ):
continue
final_arguments.append( argument )
extra_data = { extra_data = {
'options': { 'options': {
'tab_size': vimsupport.GetIntValue( 'shiftwidth()' ), 'tab_size': vimsupport.GetIntValue( 'shiftwidth()' ),
@ -335,7 +343,8 @@ class YouCompleteMe( object ):
if has_range: if has_range:
extra_data.update( vimsupport.BuildRange( start_line, end_line ) ) extra_data.update( vimsupport.BuildRange( start_line, end_line ) )
self._AddExtraConfDataIfNeeded( extra_data ) self._AddExtraConfDataIfNeeded( extra_data )
return SendCommandRequest( arguments, completer, modifiers, extra_data )
return SendCommandRequest( final_arguments, modifiers, extra_data )
def GetDefinedSubcommands( self ): def GetDefinedSubcommands( self ):