diff --git a/python/ycm/tests/postcomplete_test.py b/python/ycm/tests/postcomplete_test.py index 5b2c788a..c953ca7e 100644 --- a/python/ycm/tests/postcomplete_test.py +++ b/python/ycm/tests/postcomplete_test.py @@ -105,204 +105,98 @@ def OnCompleteDone_NoActionNoError_test( ycm, *args ): ycm.OnCompleteDone() -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @YouCompleteMeInstance() -def FilterToCompletedCompletions_NewVim_MatchIsReturned_test( ycm, *args ): +def FilterToCompletedCompletions_MatchIsReturned_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'Test' ) ] result = ycm._FilterToMatchingCompletions( completions, False ) eq_( list( result ), completions ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'A' ) ) @YouCompleteMeInstance() -def FilterToCompletedCompletions_NewVim_ShortTextDoesntRaise_test( ycm, *args ): +def FilterToCompletedCompletions_ShortTextDoesntRaise_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'AAA' ) ] ycm._FilterToMatchingCompletions( completions, False ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @YouCompleteMeInstance() -def FilterToCompletedCompletions_NewVim_ExactMatchIsReturned_test( ycm, *args ): +def FilterToCompletedCompletions_ExactMatchIsReturned_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'Test' ) ] result = ycm._FilterToMatchingCompletions( completions, False ) eq_( list( result ), completions ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( ' Quote' ) ) @YouCompleteMeInstance() -def FilterToCompletedCompletions_NewVim_NonMatchIsntReturned_test( ycm, *args ): +def FilterToCompletedCompletions_NonMatchIsntReturned_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'A' ) ] result = ycm._FilterToMatchingCompletions( completions, False ) assert_that( list( result ), empty() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( '†es†' ) ) @YouCompleteMeInstance() -def FilterToCompletedCompletions_NewVim_Unicode_test( ycm, *args ): +def FilterToCompletedCompletions_Unicode_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = '†es†' ) ] result = ycm._FilterToMatchingCompletions( completions, False ) eq_( list( result ), completions ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Test' ) -@YouCompleteMeInstance() -def FilterToCompletedCompletions_OldVim_MatchIsReturned_test( ycm, *args ): - completions = [ BuildCompletion( insertion_text = 'Test' ) ] - result = ycm._FilterToMatchingCompletions( completions, False ) - eq_( list( result ), completions ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' ) -@YouCompleteMeInstance() -def FilterToCompletedCompletions_OldVim_ShortTextDoesntRaise_test( ycm, - *args ): - completions = [ BuildCompletion( insertion_text = 'AAA' ) ] - ycm._FilterToMatchingCompletions( completions, False ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' ) -@YouCompleteMeInstance() -def FilterToCompletedCompletions_OldVim_ExactMatchIsReturned_test( ycm, - *args ): - completions = [ BuildCompletion( insertion_text = 'Test' ) ] - result = ycm._FilterToMatchingCompletions( completions, False ) - eq_( list( result ), completions ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) -@YouCompleteMeInstance() -def FilterToCompletedCompletions_OldVim_NonMatchIsntReturned_test( ycm, - *args ): - completions = [ BuildCompletion( insertion_text = 'A' ) ] - result = ycm._FilterToMatchingCompletions( completions, False ) - assert_that( list( result ), empty() ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniçø∂¢' ) -@YouCompleteMeInstance() -def FilterToCompletedCompletions_OldVim_Unicode_test( ycm, *args ): - completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ] - result = ycm._FilterToMatchingCompletions( completions, False ) - assert_that( list( result ), empty() ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' ) -@YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_MatchIsReturned_test( # noqa - ycm, *args ): - completions = [ BuildCompletion( insertion_text = 'Test' ) ] - result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) - eq_( result, True ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'X' ) -@YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ShortTextDoesntRaise_test( # noqa - ycm, *args ): - completions = [ BuildCompletion( insertion_text = "AAA" ) ] - ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Test' ) -@YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_ExactMatchIsntReturned_test( # noqa - ycm, *args ): - completions = [ BuildCompletion( insertion_text = 'Test' ) ] - result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) - eq_( result, False ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) -@YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_NonMatchIsntReturned_test( # noqa - ycm, *args ): - completions = [ BuildCompletion( insertion_text = 'A' ) ] - result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) - eq_( result, False ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' ) -@YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_OldVim_Unicode_test( - ycm, *args ): - completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ] - result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) - eq_( result, True ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Te' ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) @YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_MatchIsReturned_test( # noqa +def HasCompletionsThatCouldBeCompletedWithMoreText_MatchIsReturned_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'Test' ) ] result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) eq_( result, True ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'X' ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) @YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ShortTextDoesntRaise_test( # noqa +def HasCompletionsThatCouldBeCompletedWithMoreText_ShortTextDoesntRaise_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'AAA' ) ] ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) @YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_ExactMatchIsntReturned_test( # noqa +def HasCompletionsThatCouldBeCompletedWithMoreText_ExactMatchIsntReturned_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'Test' ) ] result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) eq_( result, False ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( ' Quote' ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Quote' ) @YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_NonMatchIsntReturned_test( # noqa +def HasCompletionsThatCouldBeCompletedWithMoreText_NonMatchIsntReturned_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = "A" ) ] result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) eq_( result, False ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Uniç' ) ) @patch( 'ycm.vimsupport.TextBeforeCursor', return_value = 'Uniç' ) @YouCompleteMeInstance() -def HasCompletionsThatCouldBeCompletedWithMoreText_NewVim_Unicode_test( +def HasCompletionsThatCouldBeCompletedWithMoreText_Unicode_test( ycm, *args ): completions = [ BuildCompletion( insertion_text = 'Uniçø∂¢' ) ] result = ycm._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) @@ -329,30 +223,18 @@ def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfNotDone_test( ycm ): eq_( [], ycm.GetCompletionsUserMayHaveCompleted() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Te' ) ) @YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_NewVim_test( # noqa +def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_test( ycm, *args ): completions = [ BuildCompletion( None ) ] with _SetupForCsharpCompletionDone( ycm, completions ): eq_( [], ycm.GetCompletionsUserMayHaveCompleted() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) @YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_ReturnEmptyIfPendingMatches_OldVim_test( # noqa - ycm, *args ): - completions = [ BuildCompletion( None ) ] - with _SetupForCsharpCompletionDone( ycm, completions ): - with patch( 'ycm.vimsupport.TextBeforeCursor', return_value = ' Te' ): - eq_( [], ycm.GetCompletionsUserMayHaveCompleted() ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) -@YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test( +def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_test( ycm, *args ): info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ] completions = [ BuildCompletion( *info ) ] @@ -362,9 +244,8 @@ def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatches_NewVim_test( eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_NewVim_test( # noqa +def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_test( # noqa ycm, *args ): info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ] completions = [ BuildCompletion( *info ), @@ -375,9 +256,8 @@ def GetCompletionsUserMayHaveCompleted_ReturnMatchIfExactMatchesEvenIfPartial_Ne eq_( [ completions[ 0 ] ], ycm.GetCompletionsUserMayHaveCompleted() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndPartial_NewVim_test( # noqa +def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNoExactMatchesAndPartial_test( # noqa ycm, *args ): info = [ 'NS', 'Test', 'Abbr', 'Menu', 'Info', 'Kind' ] completions = [ BuildCompletion( insertion_text = info[ 0 ] ), @@ -388,27 +268,17 @@ def GetCompletionsUserMayHaveCompleted_DontReturnMatchIfNontExactMatchesAndParti eq_( [], ycm.GetCompletionsUserMayHaveCompleted() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = True ) @patch( 'ycm.vimsupport.GetVariableValue', GetVariableValue_CompleteItemIs( 'Test' ) ) @YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_NewVim_test( - ycm, *args ): +def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_test( ycm, *args ): completions = [ BuildCompletion( None ) ] with _SetupForCsharpCompletionDone( ycm, completions ): eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) -@YouCompleteMeInstance() -def GetCompletionsUserMayHaveCompleted_ReturnMatchIfMatches_OldVim_test( - ycm, *args ): - completions = [ BuildCompletion( None ) ] - with _SetupForCsharpCompletionDone( ycm, completions ): - eq_( completions, ycm.GetCompletionsUserMayHaveCompleted() ) - - -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) +@patch( 'ycm.vimsupport.GetVariableValue', + GetVariableValue_CompleteItemIs( 'Test' ) ) @YouCompleteMeInstance() def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( ycm, *args ): with _SetupForCsharpCompletionDone( ycm, [] ): @@ -416,7 +286,8 @@ def PostCompleteCsharp_EmptyDoesntInsertNamespace_test( ycm, *args ): ok_( not vimsupport.InsertNamespace.called ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) +@patch( 'ycm.vimsupport.GetVariableValue', + GetVariableValue_CompleteItemIs( 'Test' ) ) @YouCompleteMeInstance() def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test( ycm, *args ): @@ -426,7 +297,8 @@ def PostCompleteCsharp_ExistingWithoutNamespaceDoesntInsertNamespace_test( ok_( not vimsupport.InsertNamespace.called ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) +@patch( 'ycm.vimsupport.GetVariableValue', + GetVariableValue_CompleteItemIs( 'Test' ) ) @YouCompleteMeInstance() def PostCompleteCsharp_ValueDoesInsertNamespace_test( ycm, *args ): namespace = 'A_NAMESPACE' @@ -436,7 +308,8 @@ def PostCompleteCsharp_ValueDoesInsertNamespace_test( ycm, *args ): vimsupport.InsertNamespace.assert_called_once_with( namespace ) -@patch( 'ycm.vimsupport.VimVersionAtLeast', return_value = False ) +@patch( 'ycm.vimsupport.GetVariableValue', + GetVariableValue_CompleteItemIs( 'Test' ) ) @patch( 'ycm.vimsupport.PresentDialog', return_value = 1 ) @YouCompleteMeInstance() def PostCompleteCsharp_InsertSecondNamespaceIfSelected_test( ycm, *args ): diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index adb85057..25c0392f 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -83,19 +83,6 @@ def TextBeforeCursor(): return ToUnicode( vim.current.line[ :CurrentColumn() ] ) -# Expects version_string in 'MAJOR.MINOR.PATCH' format, e.g. '7.4.301' -def VimVersionAtLeast( version_string ): - major, minor, patch = [ int( x ) for x in version_string.split( '.' ) ] - - # For Vim 7.4.301, v:version is '704' - actual_major_and_minor = GetIntValue( 'v:version' ) - matching_major_and_minor = major * 100 + minor - if actual_major_and_minor != matching_major_and_minor: - return actual_major_and_minor > matching_major_and_minor - - return GetBoolValue( 'has("patch{0}")'.format( patch ) ) - - # Note the difference between buffer OPTIONS and VARIABLES; the two are not # the same. def GetBufferOption( buffer_object, option ): diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 08c4d335..254ce200 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -28,7 +28,6 @@ import base64 import json import logging import os -import re import signal import vim from subprocess import PIPE @@ -442,31 +441,6 @@ class YouCompleteMe( object ): def _FilterToMatchingCompletions( self, completions, full_match_only ): - self._PatchBasedOnVimVersion() - return self._FilterToMatchingCompletions( completions, full_match_only) - - - def _HasCompletionsThatCouldBeCompletedWithMoreText( self, completions ): - self._PatchBasedOnVimVersion() - return self._HasCompletionsThatCouldBeCompletedWithMoreText( completions ) - - - def _PatchBasedOnVimVersion( self ): - if vimsupport.VimVersionAtLeast( "7.4.774" ): - self._HasCompletionsThatCouldBeCompletedWithMoreText = \ - self._HasCompletionsThatCouldBeCompletedWithMoreText_NewerVim - self._FilterToMatchingCompletions = \ - self._FilterToMatchingCompletions_NewerVim - else: - self._FilterToMatchingCompletions = \ - self._FilterToMatchingCompletions_OlderVim - self._HasCompletionsThatCouldBeCompletedWithMoreText = \ - self._HasCompletionsThatCouldBeCompletedWithMoreText_OlderVim - - - def _FilterToMatchingCompletions_NewerVim( self, - completions, - full_match_only ): """Filter to completions matching the item Vim said was completed""" completed = vimsupport.GetVariableValue( 'v:completed_item' ) for completion in completions: @@ -482,24 +456,7 @@ class YouCompleteMe( object ): yield completion - def _FilterToMatchingCompletions_OlderVim( self, completions, - full_match_only ): - """ Filter to completions matching the buffer text """ - if full_match_only: - return # Only supported in 7.4.774+ - # No support for multiple line completions - text = vimsupport.TextBeforeCursor() - for completion in completions: - word = completion[ "insertion_text" ] - # Trim complete-ending character if needed - text = re.sub( r"[^a-zA-Z0-9_]$", "", text ) - buffer_text = text[ -1 * len( word ) : ] - if buffer_text == word: - yield completion - - - def _HasCompletionsThatCouldBeCompletedWithMoreText_NewerVim( self, - completions ): + def _HasCompletionsThatCouldBeCompletedWithMoreText( self, completions ): completed_item = vimsupport.GetVariableValue( 'v:completed_item' ) if not completed_item: return False @@ -526,19 +483,6 @@ class YouCompleteMe( object ): return False - def _HasCompletionsThatCouldBeCompletedWithMoreText_OlderVim( self, - completions ): - # No support for multiple line completions - text = vimsupport.TextBeforeCursor() - for completion in completions: - word = utils.ToUnicode( - ConvertCompletionDataToVimData( completion )[ 'word' ] ) - for i in range( 1, len( word ) - 1 ): # Excluding full word - if text[ -1 * i : ] == word[ : i ]: - return True - return False - - def _OnCompleteDone_Csharp( self ): completions = self.GetCompletionsUserMayHaveCompleted() namespaces = [ self._GetRequiredNamespaceImport( c )