Refactoring out some vim.eval calls

s:completion_start_column should not be evaled in Python code. That was a
stopgap measure that ended up lasting far longer than intended.
This commit is contained in:
Strahinja Val Markovic 2013-04-09 19:25:53 -07:00
parent 27d73e0d51
commit 77fbd80c89
6 changed files with 24 additions and 19 deletions

View File

@ -420,15 +420,16 @@ function! s:InvokeCompletion()
endfunction
function! s:CompletionsForQuery( query, use_filetype_completer )
function! s:CompletionsForQuery( query, use_filetype_completer,
\ completion_start_column )
if a:use_filetype_completer
py completer = ycm_state.GetFiletypeCompleter()
else
py completer = ycm_state.GetIdentifierCompleter()
endif
" TODO: don't trigger on a dot inside a string constant
py completer.CandidatesForQueryAsync( vim.eval( 'a:query' ) )
py completer.CandidatesForQueryAsync( vim.eval( 'a:query' ),
\ int( vim.eval( 'a:completion_start_column' ) ) )
let l:results_ready = 0
while !l:results_ready
@ -481,7 +482,8 @@ function! youcompleteme#Complete( findstart, base )
endif
return s:completion_start_column
else
return s:CompletionsForQuery( a:base, s:should_use_filetype_completion )
return s:CompletionsForQuery( a:base, s:should_use_filetype_completion,
\ s:completion_start_column )
endif
endfunction

View File

@ -45,7 +45,7 @@ class IdentifierCompleter( Completer ):
return query_length >= MIN_NUM_CHARS
def CandidatesForQueryAsync( self, query ):
def CandidatesForQueryAsync( self, query, unused_start_column ):
filetype = vim.eval( "&filetype" )
self.completions_future = self.completer.CandidatesForQueryAndTypeAsync(
utils.SanitizeQuery( query ),

View File

@ -42,7 +42,7 @@ class OmniCompleter( Completer ):
return super( OmniCompleter, self ).ShouldUseNowInner( start_column )
def CandidatesForQueryAsyncInner( self, query ):
def CandidatesForQueryAsyncInner( self, query, unused_start_column ):
if not self.omnifunc:
self.stored_candidates = None
return

View File

@ -113,6 +113,7 @@ class Completer( object ):
self.triggers_for_filetype = TriggersForFiletype()
self.completions_future = None
self.completions_cache = None
self.completion_start_column = None
# It's highly likely you DON'T want to override this function but the *Inner
@ -123,7 +124,8 @@ class Completer( object ):
self.completions_cache = None
previous_results_were_empty = ( self.completions_cache and
self.completions_cache.CacheValid() and
self.completions_cache.CacheValid(
start_column ) and
not self.completions_cache.raw_completions )
return inner_says_yes and not previous_results_were_empty
@ -153,15 +155,18 @@ class Completer( object ):
# It's highly likely you DON'T want to override this function but the *Inner
# version of it.
def CandidatesForQueryAsync( self, query ):
if query and self.completions_cache and self.completions_cache.CacheValid():
def CandidatesForQueryAsync( self, query, start_column ):
self.completion_start_column = start_column
if query and self.completions_cache and self.completions_cache.CacheValid(
start_column ):
self.completions_cache.filtered_completions = (
self.FilterAndSortCandidates(
self.completions_cache.raw_completions,
query ) )
else:
self.completions_cache = None
self.CandidatesForQueryAsyncInner( query )
self.CandidatesForQueryAsyncInner( query, start_column )
def FilterAndSortCandidates( self, candidates, query ):
@ -178,7 +183,7 @@ class Completer( object ):
query )
def CandidatesForQueryAsyncInner( self, query ):
def CandidatesForQueryAsyncInner( self, query, start_column ):
pass
@ -208,8 +213,7 @@ class Completer( object ):
self.completions_cache = CompletionsCache()
self.completions_cache.raw_completions = self.CandidatesFromStoredRequestInner()
self.completions_cache.line, _ = vimsupport.CurrentLineAndColumn()
self.completions_cache.column = int(
vim.eval( "s:completion_start_column" ) )
self.completions_cache.column = self.completion_start_column
return self.completions_cache.raw_completions
@ -298,9 +302,9 @@ class CompletionsCache( object ):
self.filtered_completions = []
def CacheValid( self ):
def CacheValid( self, start_column ):
completion_line, _ = vimsupport.CurrentLineAndColumn()
completion_column = int( vim.eval( "s:completion_start_column" ) )
completion_column = start_column
return completion_line == self.line and completion_column == self.column

View File

@ -84,7 +84,7 @@ class ClangCompleter( Completer ):
return files
def CandidatesForQueryAsync( self, query ):
def CandidatesForQueryAsync( self, query, start_column ):
filename = vim.current.buffer.name
if not filename:
@ -108,8 +108,7 @@ class ClangCompleter( Completer ):
files = self.GetUnsavedFilesVector()
line, _ = vim.current.window.cursor
# TODO: this should be a function parameter
column = int( vim.eval( "s:completion_start_column" ) ) + 1
column = start_column + 1
self.completions_future = (
self.completer.CandidatesForQueryAndLocationInFileAsync(
query,

View File

@ -64,7 +64,7 @@ class JediCompleter( Completer ):
return [ 'python' ]
def CandidatesForQueryAsyncInner( self, unused_query ):
def CandidatesForQueryAsyncInner( self, unused_query, unused_start_column ):
self._candidates = None
self._candidates_ready.clear()
self._query_ready.set()