Using the pyeval func introduced in vim 7.3.584

This makes the whole plugin much faster since we now don't need to serialize and
deserialize the return values from python funcs before we can use them in Vim.
Oh God I've been waiting for something like this for so long... using this also
forces us to demand vim 7.3.584 or higher.
This commit is contained in:
Strahinja Val Markovic 2012-07-21 10:10:19 -07:00
parent 964c42068e
commit ad859ee002
3 changed files with 22 additions and 54 deletions

View File

@ -102,12 +102,9 @@ endfunction
function! s:AddIdentifierIfNeeded() function! s:AddIdentifierIfNeeded()
py vim.command( "let should_add_identifier = " + if pyeval( 'ycm.ShouldAddIdentifier()' )
\ str( int( ycm.ShouldAddIdentifier() ) ) ) py identcomp.AddPreviousIdentifier()
if should_add_identifier != 1
return
endif endif
py identcomp.AddPreviousIdentifier()
endfunction endfunction
@ -162,29 +159,17 @@ function! s:IdentifierCompletion(query)
return [] return []
endif endif
py identcomp.CandidatesForQueryAsync( vim.eval('a:query') ) py identcomp.CandidatesForQueryAsync( vim.eval( 'a:query' ) )
let l:results_ready = 0 let l:results_ready = 0
while !l:results_ready while !l:results_ready
py << EOF let l:results_ready = pyeval( 'identcomp.AsyncCandidateRequestReady()' )
results_ready = identcomp.AsyncCandidateRequestReady()
if results_ready:
vim.command( 'let l:results_ready = 1' )
EOF
if complete_check() if complete_check()
return { 'words' : [], 'refresh' : 'always'} return { 'words' : [], 'refresh' : 'always'}
endif endif
endwhile endwhile
let l:results = [] let l:results = pyeval( 'identcomp.CandidatesFromStoredRequest()' )
py << EOF
results = identcomp.CandidatesFromStoredRequest()
result_string = ycm.StringVectorToString( results )
if results:
vim.command( 'let l:results = ' + result_string )
EOF
let s:searched_and_no_results_found = len( l:results ) == 0 let s:searched_and_no_results_found = len( l:results ) == 0
" We need a very recent version of vim for this to work; otherwise, even " We need a very recent version of vim for this to work; otherwise, even
@ -200,29 +185,17 @@ endfunction
function! s:ClangCompletion( query ) function! s:ClangCompletion( query )
" TODO: don't trigger on a dot inside a string constant " TODO: don't trigger on a dot inside a string constant
py clangcomp.CandidatesForQueryAsync( vim.eval('a:query') ) py clangcomp.CandidatesForQueryAsync( vim.eval( 'a:query' ) )
let l:results_ready = 0 let l:results_ready = 0
while !l:results_ready while !l:results_ready
py << EOF let l:results_ready = pyeval( 'clangcomp.AsyncCandidateRequestReady()' )
results_ready = clangcomp.AsyncCandidateRequestReady()
if results_ready:
vim.command( 'let l:results_ready = 1' )
EOF
if complete_check() if complete_check()
return { 'words' : [], 'refresh' : 'always'} return { 'words' : [], 'refresh' : 'always'}
endif endif
endwhile endwhile
let l:results = [] let l:results = pyeval( 'clangcomp.CandidatesFromStoredRequest()' )
py << EOF
results = clangcomp.CandidatesFromStoredRequest()
result_string = ycm.CompletionDataVectorToString( results )
if results:
vim.command( 'let l:results = ' + result_string )
EOF
let s:searched_and_no_results_found = len( l:results ) == 0 let s:searched_and_no_results_found = len( l:results ) == 0
return { 'words' : l:results, 'refresh' : 'always' } return { 'words' : l:results, 'refresh' : 'always' }
endfunction endfunction
@ -231,12 +204,9 @@ endfunction
" This is our main entry point. This is what vim calls to get completions. " This is our main entry point. This is what vim calls to get completions.
function! youcompleteme#Complete( findstart, base ) function! youcompleteme#Complete( findstart, base )
if a:findstart if a:findstart
py << EOF let s:completion_start_column = pyeval( 'ycm.CompletionStartColumn()' )
start_column = ycm.CompletionStartColumn() let s:should_use_clang =
vim.command( 'let s:completion_start_column = ' + str( start_column ) ) \ pyeval( 'ycm.ShouldUseClang(' . s:completion_start_column . ')' )
vim.command( 'let s:should_use_clang = ' +
str( int( ycm.ShouldUseClang( start_column ) ) ) )
EOF
if ( s:should_use_clang ) if ( s:should_use_clang )
return s:completion_start_column return s:completion_start_column

View File

@ -17,6 +17,11 @@
if exists("g:loaded_youcompleteme") if exists("g:loaded_youcompleteme")
finish finish
elseif v:version < 703 || !has( 'patch584' )
echohl WarningMsg |
\ echomsg "YouCompleteMe unavailable: requires Vim 7.3.584+" |
\ echohl None
finish
endif endif
let g:loaded_youcompleteme = 1 let g:loaded_youcompleteme = 1

View File

@ -134,6 +134,12 @@ class ClangCompleter( Completer ):
files ) files )
def CandidatesFromStoredRequest( self ):
if not self.future:
return []
return [ CompletionDataToDict( x ) for x in self.future.GetResults() ]
def GetUnsavedBuffers(): def GetUnsavedBuffers():
def BufferModified( buffer_number ): def BufferModified( buffer_number ):
to_eval = 'getbufvar({0}, "&mod")'.format( buffer_number ) to_eval = 'getbufvar({0}, "&mod")'.format( buffer_number )
@ -142,15 +148,6 @@ def GetUnsavedBuffers():
return ( x for x in vim.buffers if BufferModified( x.number ) ) return ( x for x in vim.buffers if BufferModified( x.number ) )
# TODO: just implement __str__/__repr__ on StringVec
def StringVectorToString( stringvec ):
result = [ "[" ]
for text in stringvec:
result.append( '"{0}",'.format( text ) )
result.append( "]" )
return ''.join( result )
def CompletionDataToDict( completion_data ): def CompletionDataToDict( completion_data ):
# see :h complete-items for a description of the dictionary fields # see :h complete-items for a description of the dictionary fields
return { return {
@ -162,10 +159,6 @@ def CompletionDataToDict( completion_data ):
} }
def CompletionDataVectorToString( datavec ):
return str( [ CompletionDataToDict( x ) for x in datavec ] )
def CurrentColumn(): def CurrentColumn():
"""Do NOT access the CurrentColumn in vim.current.line. It doesn't exist yet. """Do NOT access the CurrentColumn in vim.current.line. It doesn't exist yet.
Only the chars before the current column exist in vim.current.line.""" Only the chars before the current column exist in vim.current.line."""