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:
parent
964c42068e
commit
ad859ee002
@ -102,12 +102,9 @@ endfunction
|
||||
|
||||
|
||||
function! s:AddIdentifierIfNeeded()
|
||||
py vim.command( "let should_add_identifier = " +
|
||||
\ str( int( ycm.ShouldAddIdentifier() ) ) )
|
||||
if should_add_identifier != 1
|
||||
return
|
||||
if pyeval( 'ycm.ShouldAddIdentifier()' )
|
||||
py identcomp.AddPreviousIdentifier()
|
||||
endif
|
||||
py identcomp.AddPreviousIdentifier()
|
||||
endfunction
|
||||
|
||||
|
||||
@ -162,29 +159,17 @@ function! s:IdentifierCompletion(query)
|
||||
return []
|
||||
endif
|
||||
|
||||
py identcomp.CandidatesForQueryAsync( vim.eval('a:query') )
|
||||
py identcomp.CandidatesForQueryAsync( vim.eval( 'a:query' ) )
|
||||
|
||||
let l:results_ready = 0
|
||||
while !l:results_ready
|
||||
py << EOF
|
||||
results_ready = identcomp.AsyncCandidateRequestReady()
|
||||
if results_ready:
|
||||
vim.command( 'let l:results_ready = 1' )
|
||||
EOF
|
||||
let l:results_ready = pyeval( 'identcomp.AsyncCandidateRequestReady()' )
|
||||
if complete_check()
|
||||
return { 'words' : [], 'refresh' : 'always'}
|
||||
endif
|
||||
endwhile
|
||||
|
||||
let l:results = []
|
||||
py << EOF
|
||||
results = identcomp.CandidatesFromStoredRequest()
|
||||
result_string = ycm.StringVectorToString( results )
|
||||
|
||||
if results:
|
||||
vim.command( 'let l:results = ' + result_string )
|
||||
EOF
|
||||
|
||||
let l:results = pyeval( 'identcomp.CandidatesFromStoredRequest()' )
|
||||
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
|
||||
@ -200,29 +185,17 @@ endfunction
|
||||
function! s:ClangCompletion( query )
|
||||
" 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
|
||||
while !l:results_ready
|
||||
py << EOF
|
||||
results_ready = clangcomp.AsyncCandidateRequestReady()
|
||||
if results_ready:
|
||||
vim.command( 'let l:results_ready = 1' )
|
||||
EOF
|
||||
let l:results_ready = pyeval( 'clangcomp.AsyncCandidateRequestReady()' )
|
||||
if complete_check()
|
||||
return { 'words' : [], 'refresh' : 'always'}
|
||||
endif
|
||||
endwhile
|
||||
|
||||
let l:results = []
|
||||
py << EOF
|
||||
results = clangcomp.CandidatesFromStoredRequest()
|
||||
result_string = ycm.CompletionDataVectorToString( results )
|
||||
|
||||
if results:
|
||||
vim.command( 'let l:results = ' + result_string )
|
||||
EOF
|
||||
|
||||
let l:results = pyeval( 'clangcomp.CandidatesFromStoredRequest()' )
|
||||
let s:searched_and_no_results_found = len( l:results ) == 0
|
||||
return { 'words' : l:results, 'refresh' : 'always' }
|
||||
endfunction
|
||||
@ -231,12 +204,9 @@ endfunction
|
||||
" This is our main entry point. This is what vim calls to get completions.
|
||||
function! youcompleteme#Complete( findstart, base )
|
||||
if a:findstart
|
||||
py << EOF
|
||||
start_column = ycm.CompletionStartColumn()
|
||||
vim.command( 'let s:completion_start_column = ' + str( start_column ) )
|
||||
vim.command( 'let s:should_use_clang = ' +
|
||||
str( int( ycm.ShouldUseClang( start_column ) ) ) )
|
||||
EOF
|
||||
let s:completion_start_column = pyeval( 'ycm.CompletionStartColumn()' )
|
||||
let s:should_use_clang =
|
||||
\ pyeval( 'ycm.ShouldUseClang(' . s:completion_start_column . ')' )
|
||||
|
||||
if ( s:should_use_clang )
|
||||
return s:completion_start_column
|
||||
|
@ -17,6 +17,11 @@
|
||||
|
||||
if exists("g:loaded_youcompleteme")
|
||||
finish
|
||||
elseif v:version < 703 || !has( 'patch584' )
|
||||
echohl WarningMsg |
|
||||
\ echomsg "YouCompleteMe unavailable: requires Vim 7.3.584+" |
|
||||
\ echohl None
|
||||
finish
|
||||
endif
|
||||
let g:loaded_youcompleteme = 1
|
||||
|
||||
|
@ -134,6 +134,12 @@ class ClangCompleter( Completer ):
|
||||
files )
|
||||
|
||||
|
||||
def CandidatesFromStoredRequest( self ):
|
||||
if not self.future:
|
||||
return []
|
||||
return [ CompletionDataToDict( x ) for x in self.future.GetResults() ]
|
||||
|
||||
|
||||
def GetUnsavedBuffers():
|
||||
def BufferModified( 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 ) )
|
||||
|
||||
|
||||
# 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 ):
|
||||
# see :h complete-items for a description of the dictionary fields
|
||||
return {
|
||||
@ -162,10 +159,6 @@ def CompletionDataToDict( completion_data ):
|
||||
}
|
||||
|
||||
|
||||
def CompletionDataVectorToString( datavec ):
|
||||
return str( [ CompletionDataToDict( x ) for x in datavec ] )
|
||||
|
||||
|
||||
def CurrentColumn():
|
||||
"""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."""
|
||||
|
Loading…
Reference in New Issue
Block a user