浏览代码

ShouldUseNow now takes a current_line param

This is now used instead of examining the vim.current.line property.
Strahinja Val Markovic 11 年之前
父节点
当前提交
22256f361d

+ 1 - 1
python/ycm/completers/all/identifier_completer.py

@@ -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 )
 
 

+ 7 - 5
python/ycm/completers/all/omni_completer.py

@@ -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 ):

+ 11 - 11
python/ycm/completers/completer.py

@@ -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 ):

+ 2 - 2
python/ycm/completers/cpp/clang_completer.py

@@ -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 ):

+ 2 - 2
python/ycm/completers/general/filename_completer.py

@@ -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 ) ) )
 
 

+ 4 - 3
python/ycm/completers/general/general_completer_store.py

@@ -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:

+ 1 - 1
python/ycm/completers/general/ultisnips_completer.py

@@ -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 )
 
 

+ 2 - 2
python/ycm/youcompleteme.py

@@ -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