ShouldUseNow now takes a current_line param
This is now used instead of examining the vim.current.line property.
This commit is contained in:
parent
cbb43ba4a5
commit
22256f361d
@ -43,7 +43,7 @@ class IdentifierCompleter( GeneralCompleter ):
|
|||||||
self.filetypes_with_keywords_loaded = set()
|
self.filetypes_with_keywords_loaded = set()
|
||||||
|
|
||||||
|
|
||||||
def ShouldUseNow( self, start_column ):
|
def ShouldUseNow( self, start_column, unused_current_line ):
|
||||||
return self.QueryLengthAboveMinThreshold( start_column )
|
return self.QueryLengthAboveMinThreshold( start_column )
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,16 +40,18 @@ class OmniCompleter( Completer ):
|
|||||||
return vimsupport.GetBoolValue( "g:ycm_cache_omnifunc" )
|
return vimsupport.GetBoolValue( "g:ycm_cache_omnifunc" )
|
||||||
|
|
||||||
|
|
||||||
def ShouldUseNow( self, start_column ):
|
def ShouldUseNow( self, start_column, current_line ):
|
||||||
if self.ShouldUseCache():
|
if self.ShouldUseCache():
|
||||||
return super( OmniCompleter, self ).ShouldUseNow( start_column )
|
return super( OmniCompleter, self ).ShouldUseNow( start_column,
|
||||||
return self.ShouldUseNowInner( 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:
|
if not self.omnifunc:
|
||||||
return False
|
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 ):
|
def CandidatesForQueryAsync( self, query, unused_start_column ):
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import vim
|
|
||||||
import ycm_core
|
import ycm_core
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
from ycm.completers.completer_utils import TriggersForFiletype
|
from ycm.completers.completer_utils import TriggersForFiletype
|
||||||
@ -36,10 +35,11 @@ class Completer( object ):
|
|||||||
calling on your Completer:
|
calling on your Completer:
|
||||||
|
|
||||||
ShouldUseNow() is called with the start column of where a potential completion
|
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
|
string should start and the current line (string) the cursor is on. For
|
||||||
cursor is on the 'r' in 'bar', start_column will be the 0-based index of 'b'
|
instance, if the user's input is 'foo.bar' and the cursor is on the 'r' in
|
||||||
in the line. Your implementation of ShouldUseNow() should return True if your
|
'bar', start_column will be the 0-based index of 'b' in the line. Your
|
||||||
semantic completer should be used and False otherwise.
|
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
|
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
|
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
|
# It's highly likely you DON'T want to override this function but the *Inner
|
||||||
# version of it.
|
# version of it.
|
||||||
def ShouldUseNow( self, start_column ):
|
def ShouldUseNow( self, start_column, current_line ):
|
||||||
inner_says_yes = self.ShouldUseNowInner( start_column )
|
inner_says_yes = self.ShouldUseNowInner( start_column, current_line )
|
||||||
if not inner_says_yes:
|
if not inner_says_yes:
|
||||||
self.completions_cache = None
|
self.completions_cache = None
|
||||||
|
|
||||||
@ -137,9 +137,8 @@ class Completer( object ):
|
|||||||
return inner_says_yes and not previous_results_were_empty
|
return inner_says_yes and not previous_results_were_empty
|
||||||
|
|
||||||
|
|
||||||
def ShouldUseNowInner( self, start_column ):
|
def ShouldUseNowInner( self, start_column, current_line ):
|
||||||
line = vim.current.line
|
line_length = len( current_line )
|
||||||
line_length = len( line )
|
|
||||||
if not line_length or start_column - 1 >= line_length:
|
if not line_length or start_column - 1 >= line_length:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -151,7 +150,7 @@ class Completer( object ):
|
|||||||
trigger_length = len( trigger )
|
trigger_length = len( trigger )
|
||||||
while True:
|
while True:
|
||||||
line_index = start_column + index
|
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
|
break
|
||||||
|
|
||||||
if abs( index ) == trigger_length:
|
if abs( index ) == trigger_length:
|
||||||
@ -164,6 +163,7 @@ class Completer( object ):
|
|||||||
query_length = vimsupport.CurrentColumn() - start_column
|
query_length = vimsupport.CurrentColumn() - start_column
|
||||||
return query_length >= MIN_NUM_CHARS
|
return query_length >= MIN_NUM_CHARS
|
||||||
|
|
||||||
|
|
||||||
# It's highly likely you DON'T want to override this function but the *Inner
|
# It's highly likely you DON'T want to override this function but the *Inner
|
||||||
# version of it.
|
# version of it.
|
||||||
def CandidatesForQueryAsync( self, query, start_column ):
|
def CandidatesForQueryAsync( self, query, start_column ):
|
||||||
|
@ -301,9 +301,9 @@ class ClangCompleter( Completer ):
|
|||||||
vimsupport.EchoText( closest_diagnostic.long_formatted_text_ )
|
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.
|
# 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 ):
|
def DebugInfo( self ):
|
||||||
|
@ -63,8 +63,8 @@ class FilenameCompleter( ThreadedCompleter ):
|
|||||||
vim.current.line[ :start_column ] ) )
|
vim.current.line[ :start_column ] ) )
|
||||||
|
|
||||||
|
|
||||||
def ShouldUseNowInner( self, start_column ):
|
def ShouldUseNowInner( self, start_column, current_line ):
|
||||||
return ( start_column and ( vim.current.line[ start_column - 1 ] == '/' or
|
return ( start_column and ( current_line[ start_column - 1 ] == '/' or
|
||||||
self.AtIncludeStatementStart( start_column ) ) )
|
self.AtIncludeStatementStart( start_column ) ) )
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,17 +58,18 @@ class GeneralCompleterStore( Completer ):
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
|
|
||||||
def ShouldUseNow( self, start_column ):
|
def ShouldUseNow( self, start_column, current_line ):
|
||||||
self._current_query_completers = []
|
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 ]
|
self._current_query_completers = [ self._filename_completer ]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
should_use_now = False
|
should_use_now = False
|
||||||
|
|
||||||
for completer in self._non_filename_completers:
|
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
|
should_use_now = should_use_now or should_use_this_completer
|
||||||
|
|
||||||
if should_use_this_completer:
|
if should_use_this_completer:
|
||||||
|
@ -33,7 +33,7 @@ class UltiSnipsCompleter( GeneralCompleter ):
|
|||||||
self._filtered_candidates = None
|
self._filtered_candidates = None
|
||||||
|
|
||||||
|
|
||||||
def ShouldUseNowInner( self, start_column ):
|
def ShouldUseNowInner( self, start_column, unused_current_line ):
|
||||||
return self.QueryLengthAboveMinThreshold( start_column )
|
return self.QueryLengthAboveMinThreshold( start_column )
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,13 +87,13 @@ class YouCompleteMe( object ):
|
|||||||
|
|
||||||
|
|
||||||
def ShouldUseGeneralCompleter( self, start_column ):
|
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 ):
|
def ShouldUseFiletypeCompleter( self, start_column ):
|
||||||
if self.FiletypeCompletionUsable():
|
if self.FiletypeCompletionUsable():
|
||||||
return self.GetFiletypeCompleter().ShouldUseNow(
|
return self.GetFiletypeCompleter().ShouldUseNow(
|
||||||
start_column )
|
start_column, vim.current.line )
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user