diff --git a/python/ycm/omni_completer.py b/python/ycm/omni_completer.py index 25ec3459c5..f74b95faca 100644 --- a/python/ycm/omni_completer.py +++ b/python/ycm/omni_completer.py @@ -57,11 +57,22 @@ def ShouldUseNow( self, request_data ): def ShouldUseNowInner( self, request_data ): - if request_data.get( 'force_semantic', False ): + if request_data[ 'force_semantic' ]: return True + if self._CurrentFiletypeCompletionDisabled(): + return False return super( OmniCompleter, self ).ShouldUseNowInner( request_data ) + def _CurrentFiletypeCompletionDisabled( self ): + filetypes = vimsupport.CurrentFiletypes() + filetype_to_disable = self.user_options[ + 'filetype_specific_completion_to_disable' ] + if '*' in filetype_to_disable: + return True + return any( [ x in filetype_to_disable for x in filetypes ] ) + + def ComputeCandidates( self, request_data ): if self.ShouldUseCache(): return super( OmniCompleter, self ).ComputeCandidates( request_data ) diff --git a/python/ycm/tests/omni_completer_test.py b/python/ycm/tests/omni_completer_test.py index 27fbc5c655..fb7a7d2fac 100644 --- a/python/ycm/tests/omni_completer_test.py +++ b/python/ycm/tests/omni_completer_test.py @@ -675,3 +675,55 @@ def Omnifunc( findstart, base ): 'completion_start_column': 1 } ) ) + + +@YouCompleteMeInstance( { + 'cache_omnifunc': 0, + 'filetype_specific_completion_to_disable': { FILETYPE: 1 }, + 'semantic_triggers': TRIGGERS } ) +def OmniCompleter_GetCompletions_FiletypeDisabled_SemanticTrigger_test( ycm ): + def Omnifunc( findstart, base ): + if findstart: + return 5 + return [ 'a', 'b', 'cdef' ] + + current_buffer = VimBuffer( 'buffer', + contents = [ 'test.' ], + filetype = FILETYPE, + omnifunc = Omnifunc ) + + with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ): + ycm.SendCompletionRequest() + assert_that( + ycm.GetCompletionResponse(), + has_entries( { + 'completions': empty(), + 'completion_start_column': 6 + } ) + ) + + +@YouCompleteMeInstance( { + 'cache_omnifunc': 0, + 'filetype_specific_completion_to_disable': { FILETYPE: 1 }, + 'semantic_triggers': TRIGGERS } ) +def OmniCompleter_GetCompletions_FiletypeDisabled_ForceSemantic_test( ycm ): + def Omnifunc( findstart, base ): + if findstart: + return 5 + return [ 'a', 'b', 'cdef' ] + + current_buffer = VimBuffer( 'buffer', + contents = [ 'test.' ], + filetype = FILETYPE, + omnifunc = Omnifunc ) + + with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 6 ) ): + ycm.SendCompletionRequest( force_semantic = True ) + assert_that( + ycm.GetCompletionResponse(), + has_entries( { + 'completions': ToBytesOnPY2( [ 'a', 'b', 'cdef' ] ), + 'completion_start_column': 6 + } ) + ) diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 89d7648102..d900c49249 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -301,8 +301,7 @@ def RestartServer( self ): def SendCompletionRequest( self, force_semantic = False ): request_data = BuildRequestData() request_data[ 'force_semantic' ] = force_semantic - if ( not self.NativeFiletypeCompletionAvailable() and - self.CurrentFiletypeCompletionEnabled() ): + if not self.NativeFiletypeCompletionUsable(): wrapped_request_data = RequestWrap( request_data ) if self._omnicomp.ShouldUseNow( wrapped_request_data ): self._latest_completion_request = OmniCompletionRequest( @@ -814,8 +813,7 @@ def CurrentFiletypeCompletionEnabled( self ): 'filetype_specific_completion_to_disable' ] if '*' in filetype_to_disable: return False - else: - return not any( [ x in filetype_to_disable for x in filetypes ] ) + return not any( [ x in filetype_to_disable for x in filetypes ] ) def ShowDetailedDiagnostic( self ):