diff --git a/README.md b/README.md index 47df8392..886ac3a0 100644 --- a/README.md +++ b/README.md @@ -877,6 +877,18 @@ Default: `[see next line]` \ 'erlang' : [':'], \ } +### The `g:ycm_cache_omnifunc` option + +Some omnicompletion engines do not work well with the YCM cache - in +particular, they might not produce all possible results for a given prefix. By +unsetting this option you can ensure that the omnicompletion engine is +requeried on every keypress. That will ensure all completions will be +presented, but might cause stuttering and lagginess if the omnifunc is slow. + +Default: `1` + + let g:ycm_cache_omnifunc = 1 + FAQ --- diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 84fe5822..b6c27cab 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -133,6 +133,8 @@ let g:ycm_semantic_triggers = \ 'erlang' : [':'], \ } ) +let g:ycm_cache_omnifunc = 1 + " On-demand loading. Let's use the autoload folder and not slow down vim's " startup procedure. augroup youcompletemeStart diff --git a/python/completers/all/omni_completer.py b/python/completers/all/omni_completer.py index a5846cd5..2c8f93be 100644 --- a/python/completers/all/omni_completer.py +++ b/python/completers/all/omni_completer.py @@ -36,12 +36,28 @@ class OmniCompleter( Completer ): return [] + def ShouldUseCache( self ): + return vimsupport.GetBoolValue( "g:ycm_cache_omnifunc" ) + + + def ShouldUseNow( self, start_column ): + if self.ShouldUseCache(): + return super( OmniCompleter, self ).ShouldUseNow( start_column ) + return self.ShouldUseNowInner( start_column ) + def ShouldUseNowInner( self, start_column ): if not self.omnifunc: return False return super( OmniCompleter, self ).ShouldUseNowInner( start_column ) + def CandidatesForQueryAsync( self, query, unused_start_column ): + if self.ShouldUseCache(): + return super( OmniCompleter, self ).CandidatesForQueryAsync( + query, unused_start_column ) + else: + return self.CandidatesForQueryAsyncInner( query, unused_start_column ) + def CandidatesForQueryAsyncInner( self, query, unused_start_column ): if not self.omnifunc: self.stored_candidates = None @@ -81,6 +97,12 @@ class OmniCompleter( Completer ): self.omnifunc = vim.eval( '&omnifunc' ) + def CandidatesFromStoredRequest( self ): + if self.ShouldUseCache(): + return super( OmniCompleter, self ).CandidatesFromStoredRequest() + else: + return self.CandidatesFromStoredRequestInner() + def CandidatesFromStoredRequestInner( self ): return self.stored_candidates if self.stored_candidates else []