Support completion FixIts for C-family languages

This commit is contained in:
micbou 2018-08-17 04:36:27 +02:00
parent d8d021537b
commit 4b4f678bef
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
4 changed files with 24 additions and 63 deletions

View File

@ -696,7 +696,7 @@ Quick Feature Summary
### C-family languages (C, C++, Objective C, Objective C++, CUDA) ### C-family languages (C, C++, Objective C, Objective C++, CUDA)
* Semantic auto-completion * Semantic auto-completion with automatic fixes
* Real-time diagnostic display * Real-time diagnostic display
* Go to include/declaration/definition (`GoTo`, etc.) * Go to include/declaration/definition (`GoTo`, etc.)
* Semantic type information for identifiers (`GetType`) * Semantic type information for identifiers (`GetType`)

View File

@ -920,7 +920,7 @@ General (all languages) ~
*youcompleteme-c-family-languages* *youcompleteme-c-family-languages*
C-family languages (C, C++, Objective C, Objective C++, CUDA) ~ C-family languages (C, C++, Objective C, Objective C++, CUDA) ~
- Semantic auto-completion - Semantic auto-completion with automatic fixes
- Real-time diagnostic display - Real-time diagnostic display
- Go to include/declaration/definition (|GoTo|, etc.) - Go to include/declaration/definition (|GoTo|, etc.)
- Semantic type information for identifiers (|GetType|) - Semantic type information for identifiers (|GetType|)
@ -3630,7 +3630,7 @@ http://valloric.github.io/YouCompleteMe/.
The author's homepage is http://val.markovic.io. The author's homepage is http://val.markovic.io.
Please do **NOT** go to #vim on freenode for support. Please contact the Please do **NOT** go to #vim on freenode for support. Please contact the
YouCompleteMe maintainers directly using the contact details below. YouCompleteMe maintainers directly using the contact details.
=============================================================================== ===============================================================================
*youcompleteme-license* *youcompleteme-license*

View File

@ -23,7 +23,6 @@ from __future__ import absolute_import
from builtins import * # noqa from builtins import * # noqa
import logging import logging
from future.utils import iteritems
from ycmd.utils import ToUnicode from ycmd.utils import ToUnicode
from ycm.client.base_request import ( BaseRequest, DisplayServerException, from ycm.client.base_request import ( BaseRequest, DisplayServerException,
MakeServerException ) MakeServerException )
@ -38,12 +37,6 @@ class CompletionRequest( BaseRequest ):
super( CompletionRequest, self ).__init__() super( CompletionRequest, self ).__init__()
self.request_data = request_data self.request_data = request_data
self._response_future = None self._response_future = None
self._complete_done_hooks = {
'cs': self._OnCompleteDone_Csharp,
'java': self._OnCompleteDone_FixIt,
'javascript': self._OnCompleteDone_FixIt,
'typescript': self._OnCompleteDone_FixIt,
}
def Start( self ): def Start( self ):
@ -88,16 +81,10 @@ class CompletionRequest( BaseRequest ):
if not self.Done(): if not self.Done():
return return
complete_done_actions = self._GetCompleteDoneHooks() if 'cs' in vimsupport.CurrentFiletypes():
for action in complete_done_actions: self._OnCompleteDone_Csharp()
action() else:
self._OnCompleteDone_FixIt()
def _GetCompleteDoneHooks( self ):
filetypes = vimsupport.CurrentFiletypes()
for key, value in iteritems( self._complete_done_hooks ):
if key in filetypes:
yield value
def _GetCompletionsUserMayHaveCompleted( self ): def _GetCompletionsUserMayHaveCompleted( self ):

View File

@ -129,63 +129,37 @@ def _SetUpCompleteDone( completions ):
yield request yield request
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
def GetCompleteDoneHooks_ResultOnCsharp_test( *args ):
request = CompletionRequest( None )
result = list( request._GetCompleteDoneHooks() )
eq_( result, [ request._OnCompleteDone_Csharp ] )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'java' ] )
def GetCompleteDoneHooks_ResultOnJava_test( *args ):
request = CompletionRequest( None )
result = list( request._GetCompleteDoneHooks() )
eq_( result, [ request._OnCompleteDone_FixIt ] )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'typescript' ] )
def GetCompleteDoneHooks_ResultOnTypeScript_test( *args ):
request = CompletionRequest( None )
result = list( request._GetCompleteDoneHooks() )
eq_( result, [ request._OnCompleteDone_FixIt ] )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] ) @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
def GetCompleteDoneHooks_EmptyOnOtherFiletype_test( *args ): def OnCompleteDone_DefaultFixIt_test( *args ):
request = CompletionRequest( None )
result = request._GetCompleteDoneHooks()
eq_( len( list( result ) ), 0 )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
def OnCompleteDone_WithActionCallsIt_test( *args ):
request = CompletionRequest( None )
request.Done = MagicMock( return_value = True )
action = MagicMock()
request._complete_done_hooks[ 'ycmtest' ] = action
request.OnCompleteDone()
ok_( action.called )
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
def OnCompleteDone_NoActionNoError_test( *args ):
request = CompletionRequest( None ) request = CompletionRequest( None )
request.Done = MagicMock( return_value = True ) request.Done = MagicMock( return_value = True )
request._OnCompleteDone_Csharp = MagicMock() request._OnCompleteDone_Csharp = MagicMock()
request._OnCompleteDone_FixIt = MagicMock() request._OnCompleteDone_FixIt = MagicMock()
request.OnCompleteDone() request.OnCompleteDone()
request._OnCompleteDone_Csharp.assert_not_called() request._OnCompleteDone_Csharp.assert_not_called()
request._OnCompleteDone_FixIt.assert_called_once_with()
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'cs' ] )
def OnCompleteDone_CsharpFixIt_test( *args ):
request = CompletionRequest( None )
request.Done = MagicMock( return_value = True )
request._OnCompleteDone_Csharp = MagicMock()
request._OnCompleteDone_FixIt = MagicMock()
request.OnCompleteDone()
request._OnCompleteDone_Csharp.assert_called_once_with()
request._OnCompleteDone_FixIt.assert_not_called() request._OnCompleteDone_FixIt.assert_not_called()
@patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] ) @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] )
def OnCompleteDone_NoActionIfNotDone_test( *args ): def OnCompleteDone_NoFixItIfNotDone_test( *args ):
request = CompletionRequest( None ) request = CompletionRequest( None )
request.Done = MagicMock( return_value = False ) request.Done = MagicMock( return_value = False )
action = MagicMock() request._OnCompleteDone_Csharp = MagicMock()
request._complete_done_hooks[ 'ycmtest' ] = action request._OnCompleteDone_FixIt = MagicMock()
request.OnCompleteDone() request.OnCompleteDone()
action.assert_not_called() request._OnCompleteDone_Csharp.assert_not_called()
request._OnCompleteDone_FixIt.assert_not_called()
def FilterToCompletedCompletions_MatchIsReturned_test(): def FilterToCompletedCompletions_MatchIsReturned_test():