From 77fbd80c893d56f4aad6c50ca4433676c9eea23f Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 9 Apr 2013 19:25:53 -0700 Subject: [PATCH] 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. --- autoload/youcompleteme.vim | 10 +++++---- python/completers/all/identifier_completer.py | 2 +- python/completers/all/omni_completer.py | 2 +- python/completers/completer.py | 22 +++++++++++-------- python/completers/cpp/clang_completer.py | 5 ++--- python/completers/python/jedi_completer.py | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index d9c37a47..350848de 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -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 diff --git a/python/completers/all/identifier_completer.py b/python/completers/all/identifier_completer.py index 8aa013a2..fcd3f07f 100644 --- a/python/completers/all/identifier_completer.py +++ b/python/completers/all/identifier_completer.py @@ -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 ), diff --git a/python/completers/all/omni_completer.py b/python/completers/all/omni_completer.py index 5e0436be..a5846cd5 100644 --- a/python/completers/all/omni_completer.py +++ b/python/completers/all/omni_completer.py @@ -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 diff --git a/python/completers/completer.py b/python/completers/completer.py index e87299af..d991e774 100644 --- a/python/completers/completer.py +++ b/python/completers/completer.py @@ -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 diff --git a/python/completers/cpp/clang_completer.py b/python/completers/cpp/clang_completer.py index ef830a26..dad9792d 100644 --- a/python/completers/cpp/clang_completer.py +++ b/python/completers/cpp/clang_completer.py @@ -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, diff --git a/python/completers/python/jedi_completer.py b/python/completers/python/jedi_completer.py index a9a94313..be80268b 100644 --- a/python/completers/python/jedi_completer.py +++ b/python/completers/python/jedi_completer.py @@ -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()