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:
parent
27d73e0d51
commit
77fbd80c89
@ -420,15 +420,16 @@ function! s:InvokeCompletion()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:CompletionsForQuery( query, use_filetype_completer )
|
function! s:CompletionsForQuery( query, use_filetype_completer,
|
||||||
|
\ completion_start_column )
|
||||||
if a:use_filetype_completer
|
if a:use_filetype_completer
|
||||||
py completer = ycm_state.GetFiletypeCompleter()
|
py completer = ycm_state.GetFiletypeCompleter()
|
||||||
else
|
else
|
||||||
py completer = ycm_state.GetIdentifierCompleter()
|
py completer = ycm_state.GetIdentifierCompleter()
|
||||||
endif
|
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
|
let l:results_ready = 0
|
||||||
while !l:results_ready
|
while !l:results_ready
|
||||||
@ -481,7 +482,8 @@ function! youcompleteme#Complete( findstart, base )
|
|||||||
endif
|
endif
|
||||||
return s:completion_start_column
|
return s:completion_start_column
|
||||||
else
|
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
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class IdentifierCompleter( Completer ):
|
|||||||
return query_length >= MIN_NUM_CHARS
|
return query_length >= MIN_NUM_CHARS
|
||||||
|
|
||||||
|
|
||||||
def CandidatesForQueryAsync( self, query ):
|
def CandidatesForQueryAsync( self, query, unused_start_column ):
|
||||||
filetype = vim.eval( "&filetype" )
|
filetype = vim.eval( "&filetype" )
|
||||||
self.completions_future = self.completer.CandidatesForQueryAndTypeAsync(
|
self.completions_future = self.completer.CandidatesForQueryAndTypeAsync(
|
||||||
utils.SanitizeQuery( query ),
|
utils.SanitizeQuery( query ),
|
||||||
|
@ -42,7 +42,7 @@ class OmniCompleter( Completer ):
|
|||||||
return super( OmniCompleter, self ).ShouldUseNowInner( start_column )
|
return super( OmniCompleter, self ).ShouldUseNowInner( start_column )
|
||||||
|
|
||||||
|
|
||||||
def CandidatesForQueryAsyncInner( self, query ):
|
def CandidatesForQueryAsyncInner( self, query, unused_start_column ):
|
||||||
if not self.omnifunc:
|
if not self.omnifunc:
|
||||||
self.stored_candidates = None
|
self.stored_candidates = None
|
||||||
return
|
return
|
||||||
|
@ -113,6 +113,7 @@ class Completer( object ):
|
|||||||
self.triggers_for_filetype = TriggersForFiletype()
|
self.triggers_for_filetype = TriggersForFiletype()
|
||||||
self.completions_future = None
|
self.completions_future = None
|
||||||
self.completions_cache = 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
|
# 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
|
self.completions_cache = None
|
||||||
|
|
||||||
previous_results_were_empty = ( self.completions_cache and
|
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 )
|
not self.completions_cache.raw_completions )
|
||||||
return inner_says_yes and not previous_results_were_empty
|
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
|
# 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 ):
|
def CandidatesForQueryAsync( self, query, start_column ):
|
||||||
if query and self.completions_cache and self.completions_cache.CacheValid():
|
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.completions_cache.filtered_completions = (
|
||||||
self.FilterAndSortCandidates(
|
self.FilterAndSortCandidates(
|
||||||
self.completions_cache.raw_completions,
|
self.completions_cache.raw_completions,
|
||||||
query ) )
|
query ) )
|
||||||
else:
|
else:
|
||||||
self.completions_cache = None
|
self.completions_cache = None
|
||||||
self.CandidatesForQueryAsyncInner( query )
|
self.CandidatesForQueryAsyncInner( query, start_column )
|
||||||
|
|
||||||
|
|
||||||
def FilterAndSortCandidates( self, candidates, query ):
|
def FilterAndSortCandidates( self, candidates, query ):
|
||||||
@ -178,7 +183,7 @@ class Completer( object ):
|
|||||||
query )
|
query )
|
||||||
|
|
||||||
|
|
||||||
def CandidatesForQueryAsyncInner( self, query ):
|
def CandidatesForQueryAsyncInner( self, query, start_column ):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -208,8 +213,7 @@ class Completer( object ):
|
|||||||
self.completions_cache = CompletionsCache()
|
self.completions_cache = CompletionsCache()
|
||||||
self.completions_cache.raw_completions = self.CandidatesFromStoredRequestInner()
|
self.completions_cache.raw_completions = self.CandidatesFromStoredRequestInner()
|
||||||
self.completions_cache.line, _ = vimsupport.CurrentLineAndColumn()
|
self.completions_cache.line, _ = vimsupport.CurrentLineAndColumn()
|
||||||
self.completions_cache.column = int(
|
self.completions_cache.column = self.completion_start_column
|
||||||
vim.eval( "s:completion_start_column" ) )
|
|
||||||
return self.completions_cache.raw_completions
|
return self.completions_cache.raw_completions
|
||||||
|
|
||||||
|
|
||||||
@ -298,9 +302,9 @@ class CompletionsCache( object ):
|
|||||||
self.filtered_completions = []
|
self.filtered_completions = []
|
||||||
|
|
||||||
|
|
||||||
def CacheValid( self ):
|
def CacheValid( self, start_column ):
|
||||||
completion_line, _ = vimsupport.CurrentLineAndColumn()
|
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
|
return completion_line == self.line and completion_column == self.column
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class ClangCompleter( Completer ):
|
|||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
def CandidatesForQueryAsync( self, query ):
|
def CandidatesForQueryAsync( self, query, start_column ):
|
||||||
filename = vim.current.buffer.name
|
filename = vim.current.buffer.name
|
||||||
|
|
||||||
if not filename:
|
if not filename:
|
||||||
@ -108,8 +108,7 @@ class ClangCompleter( Completer ):
|
|||||||
files = self.GetUnsavedFilesVector()
|
files = self.GetUnsavedFilesVector()
|
||||||
|
|
||||||
line, _ = vim.current.window.cursor
|
line, _ = vim.current.window.cursor
|
||||||
# TODO: this should be a function parameter
|
column = start_column + 1
|
||||||
column = int( vim.eval( "s:completion_start_column" ) ) + 1
|
|
||||||
self.completions_future = (
|
self.completions_future = (
|
||||||
self.completer.CandidatesForQueryAndLocationInFileAsync(
|
self.completer.CandidatesForQueryAndLocationInFileAsync(
|
||||||
query,
|
query,
|
||||||
|
@ -64,7 +64,7 @@ class JediCompleter( Completer ):
|
|||||||
return [ 'python' ]
|
return [ 'python' ]
|
||||||
|
|
||||||
|
|
||||||
def CandidatesForQueryAsyncInner( self, unused_query ):
|
def CandidatesForQueryAsyncInner( self, unused_query, unused_start_column ):
|
||||||
self._candidates = None
|
self._candidates = None
|
||||||
self._candidates_ready.clear()
|
self._candidates_ready.clear()
|
||||||
self._query_ready.set()
|
self._query_ready.set()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user