ShouldUseNow now takes a current_line param

This is now used instead of examining the vim.current.line property.
This commit is contained in:
Strahinja Val Markovic 2013-09-01 20:17:37 -07:00
parent cbb43ba4a5
commit 22256f361d
8 changed files with 30 additions and 27 deletions

View File

@ -43,7 +43,7 @@ class IdentifierCompleter( GeneralCompleter ):
self.filetypes_with_keywords_loaded = set()
def ShouldUseNow( self, start_column ):
def ShouldUseNow( self, start_column, unused_current_line ):
return self.QueryLengthAboveMinThreshold( start_column )

View File

@ -40,16 +40,18 @@ class OmniCompleter( Completer ):
return vimsupport.GetBoolValue( "g:ycm_cache_omnifunc" )
def ShouldUseNow( self, start_column ):
def ShouldUseNow( self, start_column, current_line ):
if self.ShouldUseCache():
return super( OmniCompleter, self ).ShouldUseNow( start_column )
return self.ShouldUseNowInner( start_column )
return super( OmniCompleter, self ).ShouldUseNow( start_column,
current_line )
return self.ShouldUseNowInner( start_column, current_line )
def ShouldUseNowInner( self, start_column ):
def ShouldUseNowInner( self, start_column, current_line ):
if not self.omnifunc:
return False
return super( OmniCompleter, self ).ShouldUseNowInner( start_column )
return super( OmniCompleter, self ).ShouldUseNowInner( start_column,
current_line )
def CandidatesForQueryAsync( self, query, unused_start_column ):

View File

@ -18,7 +18,6 @@
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
import abc
import vim
import ycm_core
from ycm import vimsupport
from ycm.completers.completer_utils import TriggersForFiletype
@ -36,10 +35,11 @@ class Completer( object ):
calling on your Completer:
ShouldUseNow() is called with the start column of where a potential completion
string should start. For instance, if the user's input is 'foo.bar' and the
cursor is on the 'r' in 'bar', start_column will be the 0-based index of 'b'
in the line. Your implementation of ShouldUseNow() should return True if your
semantic completer should be used and False otherwise.
string should start and the current line (string) the cursor is on. For
instance, if the user's input is 'foo.bar' and the cursor is on the 'r' in
'bar', start_column will be the 0-based index of 'b' in the line. Your
implementation of ShouldUseNow() should return True if your semantic completer
should be used and False otherwise.
This is important to get right. You want to return False if you can't provide
completions because then the identifier completer will kick in, and that's
@ -125,8 +125,8 @@ class Completer( object ):
# It's highly likely you DON'T want to override this function but the *Inner
# version of it.
def ShouldUseNow( self, start_column ):
inner_says_yes = self.ShouldUseNowInner( start_column )
def ShouldUseNow( self, start_column, current_line ):
inner_says_yes = self.ShouldUseNowInner( start_column, current_line )
if not inner_says_yes:
self.completions_cache = None
@ -137,9 +137,8 @@ class Completer( object ):
return inner_says_yes and not previous_results_were_empty
def ShouldUseNowInner( self, start_column ):
line = vim.current.line
line_length = len( line )
def ShouldUseNowInner( self, start_column, current_line ):
line_length = len( current_line )
if not line_length or start_column - 1 >= line_length:
return False
@ -151,7 +150,7 @@ class Completer( object ):
trigger_length = len( trigger )
while True:
line_index = start_column + index
if line_index < 0 or line[ line_index ] != trigger[ index ]:
if line_index < 0 or current_line[ line_index ] != trigger[ index ]:
break
if abs( index ) == trigger_length:
@ -164,6 +163,7 @@ class Completer( object ):
query_length = vimsupport.CurrentColumn() - start_column
return query_length >= MIN_NUM_CHARS
# It's highly likely you DON'T want to override this function but the *Inner
# version of it.
def CandidatesForQueryAsync( self, query, start_column ):

View File

@ -301,9 +301,9 @@ class ClangCompleter( Completer ):
vimsupport.EchoText( closest_diagnostic.long_formatted_text_ )
def ShouldUseNow( self, start_column ):
def ShouldUseNow( self, start_column, current_line ):
# We don't want to use the Completer API cache, we use one in the C++ code.
return self.ShouldUseNowInner( start_column )
return self.ShouldUseNowInner( start_column, current_line )
def DebugInfo( self ):

View File

@ -63,8 +63,8 @@ class FilenameCompleter( ThreadedCompleter ):
vim.current.line[ :start_column ] ) )
def ShouldUseNowInner( self, start_column ):
return ( start_column and ( vim.current.line[ start_column - 1 ] == '/' or
def ShouldUseNowInner( self, start_column, current_line ):
return ( start_column and ( current_line[ start_column - 1 ] == '/' or
self.AtIncludeStatementStart( start_column ) ) )

View File

@ -58,17 +58,18 @@ class GeneralCompleterStore( Completer ):
return set()
def ShouldUseNow( self, start_column ):
def ShouldUseNow( self, start_column, current_line ):
self._current_query_completers = []
if self._filename_completer.ShouldUseNow( start_column ):
if self._filename_completer.ShouldUseNow( start_column, current_line ):
self._current_query_completers = [ self._filename_completer ]
return True
should_use_now = False
for completer in self._non_filename_completers:
should_use_this_completer = completer.ShouldUseNow( start_column )
should_use_this_completer = completer.ShouldUseNow( start_column,
current_line )
should_use_now = should_use_now or should_use_this_completer
if should_use_this_completer:

View File

@ -33,7 +33,7 @@ class UltiSnipsCompleter( GeneralCompleter ):
self._filtered_candidates = None
def ShouldUseNowInner( self, start_column ):
def ShouldUseNowInner( self, start_column, unused_current_line ):
return self.QueryLengthAboveMinThreshold( start_column )

View File

@ -87,13 +87,13 @@ class YouCompleteMe( object ):
def ShouldUseGeneralCompleter( self, start_column ):
return self.gencomp.ShouldUseNow( start_column )
return self.gencomp.ShouldUseNow( start_column, vim.current.line )
def ShouldUseFiletypeCompleter( self, start_column ):
if self.FiletypeCompletionUsable():
return self.GetFiletypeCompleter().ShouldUseNow(
start_column )
start_column, vim.current.line )
return False