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 2b0c34f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,8 @@ dictionary with keys being filetype strings (like `python`, `cpp` etc) and
values being unimportant (the dictionary is used like a hash set, meaning that
only the keys matter). The listed filetypes will be ignored by the YCM semantic
completion engine, but the identifier-based completion engine will still trigger
in files of those filetypes.
in files of those filetypes. Vim's omnifunc can still be triggered with the
`<C-Space>` key.

Note that even if semantic completion is not turned off for a specific filetype,
you will not get semantic completion if the semantic engine does not support
Expand Down
3 changes: 2 additions & 1 deletion doc/youcompleteme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,8 @@ dictionary with keys being filetype strings (like 'python', 'cpp' etc) and
values being unimportant (the dictionary is used like a hash set, meaning that
only the keys matter). The listed filetypes will be ignored by the YCM semantic
completion engine, but the identifier-based completion engine will still
trigger in files of those filetypes.
trigger in files of those filetypes. Vim's omnifunc can still be triggered with
the '<C-Space>' key.

Note that even if semantic completion is not turned off for a specific
filetype, you will not get semantic completion if the semantic engine does not
Expand Down
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 2b0c34f

Please sign in to comment.