Skip to content

Commit

Permalink
Do not disable omnifunc when filetype completion is disabled
Browse files Browse the repository at this point in the history
Allow users to still trigger Vim's omnifunc through C-Space when the
g:ycm_filetype_specific_completion_to_disable option is set for the current
filetype.
  • Loading branch information
micbou committed Apr 6, 2018
1 parent 37965fe commit ad13b62
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
13 changes: 12 additions & 1 deletion python/ycm/omni_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
52 changes: 52 additions & 0 deletions python/ycm/tests/omni_completer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
} )
)
6 changes: 2 additions & 4 deletions python/ycm/youcompleteme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 ):
Expand Down

0 comments on commit ad13b62

Please sign in to comment.