Making the omni completer more robust
- There was a bug in not calling int() on the result of the first call to the omnifunc. - We need to be more resilient to badly written omnifuncs and check that the result of the second call is a list or a dict with a list, as the vim docs say the omnifunc should return on the second call. One of the two fixes probably fixes #198 but since I can't repro the error, I can't be sure.
This commit is contained in:
parent
4f12febb44
commit
74021144c0
@ -21,6 +21,10 @@ import vim
|
|||||||
import vimsupport
|
import vimsupport
|
||||||
from completers.completer import Completer
|
from completers.completer import Completer
|
||||||
|
|
||||||
|
OMNIFUNC_RETURNED_BAD_VALUE = 'Omnifunc returned bad value to YCM!'
|
||||||
|
OMNIFUNC_NOT_LIST = ( 'Omnifunc did not return a list or a dict with a "words" '
|
||||||
|
' list when expected.' )
|
||||||
|
|
||||||
class OmniCompleter( Completer ):
|
class OmniCompleter( Completer ):
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
super( OmniCompleter, self ).__init__()
|
super( OmniCompleter, self ).__init__()
|
||||||
@ -43,7 +47,8 @@ class OmniCompleter( Completer ):
|
|||||||
self.stored_candidates = None
|
self.stored_candidates = None
|
||||||
return
|
return
|
||||||
|
|
||||||
return_value = vim.eval( self.omnifunc + '(1,"")' )
|
try:
|
||||||
|
return_value = int( vim.eval( self.omnifunc + '(1,"")' ) )
|
||||||
if return_value < 0:
|
if return_value < 0:
|
||||||
self.stored_candidates = None
|
self.stored_candidates = None
|
||||||
return
|
return
|
||||||
@ -56,7 +61,16 @@ class OmniCompleter( Completer ):
|
|||||||
items = vim.eval( ''.join( omnifunc_call ) )
|
items = vim.eval( ''.join( omnifunc_call ) )
|
||||||
if hasattr( items, 'words' ):
|
if hasattr( items, 'words' ):
|
||||||
items = items.words
|
items = items.words
|
||||||
|
if not hasattr( items, '__iter__' ):
|
||||||
|
raise TypeError( OMNIFUNC_NOT_LIST )
|
||||||
|
|
||||||
self.stored_candidates = filter( bool, items )
|
self.stored_candidates = filter( bool, items )
|
||||||
|
except (TypeError, ValueError) as error:
|
||||||
|
vimsupport.PostVimMessage(
|
||||||
|
OMNIFUNC_RETURNED_BAD_VALUE + ' ' + str( error ) )
|
||||||
|
self.stored_candidates = None
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def AsyncCandidateRequestReadyInner( self ):
|
def AsyncCandidateRequestReadyInner( self ):
|
||||||
@ -68,5 +82,5 @@ class OmniCompleter( Completer ):
|
|||||||
|
|
||||||
|
|
||||||
def CandidatesFromStoredRequestInner( self ):
|
def CandidatesFromStoredRequestInner( self ):
|
||||||
return self.stored_candidates
|
return self.stored_candidates if self.stored_candidates else []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user