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 13, 2018
1 parent 37965fe commit e96ef7c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 14 deletions.
6 changes: 5 additions & 1 deletion python/ycm/omni_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ def ShouldUseNow( self, request_data ):


def ShouldUseNowInner( self, request_data ):
if request_data.get( 'force_semantic', False ):
if request_data[ 'force_semantic' ]:
return True
disabled_filetypes = self.user_options[
'filetype_specific_completion_to_disable' ]
if not vimsupport.CurrentFiletypesEnabled( disabled_filetypes ):
return False
return super( OmniCompleter, self ).ShouldUseNowInner( request_data )


Expand Down
106 changes: 106 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,109 @@ 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': { '*': 1 },
'semantic_triggers': TRIGGERS } )
def OmniCompleter_GetCompletions_AllFiletypesDisabled_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
} )
)


@YouCompleteMeInstance( {
'cache_omnifunc': 0,
'filetype_specific_completion_to_disable': { '*': 1 },
'semantic_triggers': TRIGGERS } )
def OmniCompleter_GetCompletions_AllFiletypesDisabled_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
} )
)
9 changes: 9 additions & 0 deletions python/ycm/vimsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,15 @@ def CurrentFiletypes():
return ToUnicode( vim.eval( "&filetype" ) ).split( '.' )


def CurrentFiletypesEnabled( disabled_filetypes ):
"""Return False if one of the current filetypes is disabled, True otherwise.
|disabled_filetypes| must be a dictionary where keys are the disabled
filetypes and values are unimportant. The special key '*' matches all
filetypes."""
return ( '*' not in disabled_filetypes and
not any( [ x in disabled_filetypes for x in CurrentFiletypes() ] ) )


def GetBufferFiletypes( bufnr ):
command = 'getbufvar({0}, "&ft")'.format( bufnr )
return ToUnicode( vim.eval( command ) ).split( '.' )
Expand Down
17 changes: 4 additions & 13 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 @@ -380,7 +379,9 @@ def NativeFiletypeCompletionAvailable( self ):


def NativeFiletypeCompletionUsable( self ):
return ( self.CurrentFiletypeCompletionEnabled() and
disabled_filetypes = self._user_options[
'filetype_specific_completion_to_disable' ]
return ( vimsupport.CurrentFiletypesEnabled( disabled_filetypes ) and
self.NativeFiletypeCompletionAvailable() )


Expand Down Expand Up @@ -808,16 +809,6 @@ def ToggleLogs( self, *filenames ):
self._CloseLogfile( logfile )


def CurrentFiletypeCompletionEnabled( self ):
filetypes = vimsupport.CurrentFiletypes()
filetype_to_disable = self._user_options[
'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 ] )


def ShowDetailedDiagnostic( self ):
with HandleServerException():
detailed_diagnostic = BaseRequest.PostDataToHandler(
Expand Down

0 comments on commit e96ef7c

Please sign in to comment.