From 5981809681a5fff2db242ada0bd056409ad6183d Mon Sep 17 00:00:00 2001 From: micbou Date: Tue, 27 Mar 2018 01:20:53 +0200 Subject: [PATCH] Support FixIts in TypeScript completions --- python/ycm/client/completion_request.py | 5 ++-- python/ycm/tests/postcomplete_test.py | 38 +++++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/python/ycm/client/completion_request.py b/python/ycm/client/completion_request.py index 00d29420..18469ade 100644 --- a/python/ycm/client/completion_request.py +++ b/python/ycm/client/completion_request.py @@ -39,7 +39,8 @@ class CompletionRequest( BaseRequest ): self._response_future = None self._complete_done_hooks = { 'cs': self._OnCompleteDone_Csharp, - 'java': self._OnCompleteDone_Java, + 'java': self._OnCompleteDone_FixIt, + 'typescript': self._OnCompleteDone_FixIt, } @@ -134,7 +135,7 @@ class CompletionRequest( BaseRequest ): vimsupport.InsertNamespace( namespace ) - def _OnCompleteDone_Java( self ): + def _OnCompleteDone_FixIt( self ): completions = self._GetCompletionsUserMayHaveCompleted() fixit_completions = [ _GetFixItCompletion( c ) for c in completions ] fixit_completions = [ f for f in fixit_completions if f ] diff --git a/python/ycm/tests/postcomplete_test.py b/python/ycm/tests/postcomplete_test.py index 813dc39b..d026781d 100644 --- a/python/ycm/tests/postcomplete_test.py +++ b/python/ycm/tests/postcomplete_test.py @@ -140,7 +140,14 @@ def GetCompleteDoneHooks_ResultOnCsharp_test( *args ): def GetCompleteDoneHooks_ResultOnJava_test( *args ): request = CompletionRequest( None ) result = list( request._GetCompleteDoneHooks() ) - eq_( result, [ request._OnCompleteDone_Java ] ) + 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' ] ) @@ -165,10 +172,10 @@ def OnCompleteDone_NoActionNoError_test( *args ): request = CompletionRequest( None ) request.Done = MagicMock( return_value = True ) request._OnCompleteDone_Csharp = MagicMock() - request._OnCompleteDone_Java = MagicMock() + request._OnCompleteDone_FixIt = MagicMock() request.OnCompleteDone() request._OnCompleteDone_Csharp.assert_not_called() - request._OnCompleteDone_Java.assert_not_called() + request._OnCompleteDone_FixIt.assert_not_called() @patch( 'ycm.vimsupport.CurrentFiletypes', return_value = [ 'ycmtest' ] ) @@ -356,73 +363,74 @@ def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( *args ): @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @patch( 'ycm.vimsupport.ReplaceChunks' ) -def PostCompleteJava_ApplyFixIt_NoFixIts_test( replace_chunks, *args ): +def PostCompleteFixIt_ApplyFixIt_NoFixIts_test( replace_chunks, *args ): completions = [ BuildCompletionFixIt( [] ) ] with _SetUpCompleteDone( completions ) as request: - request._OnCompleteDone_Java() + request._OnCompleteDone_FixIt() replace_chunks.assert_not_called() @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @patch( 'ycm.vimsupport.ReplaceChunks' ) -def PostCompleteJava_ApplyFixIt_EmptyFixIt_test( replace_chunks, *args ): +def PostCompleteFixIt_ApplyFixIt_EmptyFixIt_test( replace_chunks, *args ): completions = [ BuildCompletionFixIt( [ { 'chunks': [] } ] ) ] with _SetUpCompleteDone( completions ) as request: - request._OnCompleteDone_Java() + request._OnCompleteDone_FixIt() replace_chunks.assert_called_once_with( [], silent = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @patch( 'ycm.vimsupport.ReplaceChunks' ) -def PostCompleteJava_ApplyFixIt_NoFixIt_test( replace_chunks, *args ): +def PostCompleteFixIt_ApplyFixIt_NoFixIt_test( replace_chunks, *args ): completions = [ BuildCompletion( ) ] with _SetUpCompleteDone( completions ) as request: - request._OnCompleteDone_Java() + request._OnCompleteDone_FixIt() replace_chunks.assert_not_called() @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @patch( 'ycm.vimsupport.ReplaceChunks' ) -def PostCompleteJava_ApplyFixIt_PickFirst_test( replace_chunks, *args ): +def PostCompleteFixIt_ApplyFixIt_PickFirst_test( replace_chunks, *args ): completions = [ BuildCompletionFixIt( [ { 'chunks': 'one' } ] ), BuildCompletionFixIt( [ { 'chunks': 'two' } ] ), ] with _SetUpCompleteDone( completions ) as request: - request._OnCompleteDone_Java() + request._OnCompleteDone_FixIt() replace_chunks.assert_called_once_with( 'one', silent = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test', user_data='0' ) ) @patch( 'ycm.vimsupport.ReplaceChunks' ) -def PostCompleteJava_ApplyFixIt_PickFirstUserData_test( replace_chunks, *args ): +def PostCompleteFixIt_ApplyFixIt_PickFirstUserData_test( replace_chunks, + *args ): completions = [ BuildCompletionFixIt( [ { 'chunks': 'one' } ] ), BuildCompletionFixIt( [ { 'chunks': 'two' } ] ), ] with _SetUpCompleteDone( completions ) as request: - request._OnCompleteDone_Java() + request._OnCompleteDone_FixIt() replace_chunks.assert_called_once_with( 'one', silent = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test', user_data='1' ) ) @patch( 'ycm.vimsupport.ReplaceChunks' ) -def PostCompleteJava_ApplyFixIt_PickSecond_test( replace_chunks, *args ): +def PostCompleteFixIt_ApplyFixIt_PickSecond_test( replace_chunks, *args ): completions = [ BuildCompletionFixIt( [ { 'chunks': 'one' } ] ), BuildCompletionFixIt( [ { 'chunks': 'two' } ] ), ] with _SetUpCompleteDone( completions ) as request: - request._OnCompleteDone_Java() + request._OnCompleteDone_FixIt() replace_chunks.assert_called_once_with( 'two', silent = True )