From ea30cb046e02907c6c3471b12554490a0f7dfb18 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sun, 5 Aug 2012 13:12:10 -0700 Subject: [PATCH] ShouldUseNow for IdentifierCompleter done and used --- autoload/youcompleteme.vim | 22 ++++++---------------- python/completers/all.py | 7 ++++--- python/vimsupport.py | 4 ++++ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 843ba37b..4d6f7440 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -205,12 +205,6 @@ endfunction function! s:CompletionsForQuery( query, use_filetype_completer ) - " TODO: needed? - if !a:use_filetype_completer && - \ strlen( a:query ) < g:ycm_min_num_of_chars_for_completion - return [] - endif - if a:use_filetype_completer py completer = ycm_state.GetFiletypeCompleterForCurrentFile() else @@ -250,16 +244,12 @@ function! youcompleteme#Complete( findstart, base ) \ pyeval( 'ycm_state.ShouldUseFiletypeCompleter(' . \ s:completion_start_column . ')' ) - " TODO: use ShouldUseIdentifierCompleter() which checks query length - if ( !s:should_use_filetype_completion ) - let l:current_column = col('.') - 1 - let l:query_length = current_column - s:completion_start_column - - if ( query_length < g:ycm_min_num_of_chars_for_completion ) - " for vim, -2 means not found but don't trigger an error message - " see :h complete-functions - return -2 - endif + if !s:should_use_filetype_completion && + \ !pyeval( 'ycm_state.ShouldUseIdentifierCompleter(' . + \ s:completion_start_column . ')' ) + " for vim, -2 means not found but don't trigger an error message + " see :h complete-functions + return -2 endif return s:completion_start_column else diff --git a/python/completers/all.py b/python/completers/all.py index e57850fe..b066a646 100644 --- a/python/completers/all.py +++ b/python/completers/all.py @@ -24,7 +24,8 @@ import ycm_core import utils MAX_IDENTIFIER_COMPLETIONS_RETURNED = 10 -MIN_NUM_CHARS = int( vim.eval( "g:ycm_min_num_of_chars_for_completion" ) ) +MIN_NUM_CHARS = int( vimsupport.GetVariableValue( + "g:ycm_min_num_of_chars_for_completion" ) ) def GetCompleter(): @@ -42,9 +43,9 @@ class IdentifierCompleter( Completer ): return set( [ 'ycm_all' ] ) - # TODO: implement this def ShouldUseNow( self, start_column ): - return True + query_length = vimsupport.CurrentColumn() - start_column + return query_length >= MIN_NUM_CHARS def CandidatesForQueryAsync( self, query ): diff --git a/python/vimsupport.py b/python/vimsupport.py index e576636e..827b5f32 100644 --- a/python/vimsupport.py +++ b/python/vimsupport.py @@ -64,3 +64,7 @@ def EscapeForVim( text ): def CurrentFiletype(): return vim.eval( "&filetype" ) + + +def GetVariableValue( variable ): + return vim.eval( variable )