Completer access now through CompletionRequest
This will make it easier to put Completers in the server.
This commit is contained in:
parent
28c3d9648c
commit
bd374a7096
@ -22,8 +22,6 @@ set cpo&vim
|
|||||||
" This needs to be called outside of a function
|
" This needs to be called outside of a function
|
||||||
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
|
let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
|
||||||
let s:searched_and_results_found = 0
|
let s:searched_and_results_found = 0
|
||||||
let s:should_use_filetype_completion = 0
|
|
||||||
let s:completion_start_column = 0
|
|
||||||
let s:omnifunc_mode = 0
|
let s:omnifunc_mode = 0
|
||||||
|
|
||||||
let s:old_cursor_position = []
|
let s:old_cursor_position = []
|
||||||
@ -497,29 +495,26 @@ function! s:InvokeCompletion()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! s:CompletionsForQuery( query, use_filetype_completer,
|
python << EOF
|
||||||
\ completion_start_column )
|
def GetCompletions( query ):
|
||||||
if a:use_filetype_completer
|
request = ycm_state.GetCurrentCompletionRequest()
|
||||||
py completer = ycm_state.GetFiletypeCompleter()
|
request.Start( query )
|
||||||
else
|
results_ready = False
|
||||||
py completer = ycm_state.GetGeneralCompleter()
|
while not results_ready:
|
||||||
endif
|
results_ready = request.Done()
|
||||||
|
if bool( int( vim.eval( 'complete_check()' ) ) ):
|
||||||
py completer.CandidatesForQueryAsync( vim.eval( 'a:query' ),
|
|
||||||
\ int( vim.eval( 'a:completion_start_column' ) ) )
|
|
||||||
|
|
||||||
let l:results_ready = 0
|
|
||||||
while !l:results_ready
|
|
||||||
let l:results_ready = pyeval( 'completer.AsyncCandidateRequestReady()' )
|
|
||||||
if complete_check()
|
|
||||||
let s:searched_and_results_found = 0
|
|
||||||
return { 'words' : [], 'refresh' : 'always'}
|
return { 'words' : [], 'refresh' : 'always'}
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
let l:results = pyeval( 'base.AdjustCandidateInsertionText( completer.CandidatesFromStoredRequest() )' )
|
results = base.AdjustCandidateInsertionText( request.Results() )
|
||||||
let s:searched_and_results_found = len( l:results ) != 0
|
return { 'words' : results, 'refresh' : 'always' }
|
||||||
return { 'words' : l:results, 'refresh' : 'always' }
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
function! s:CompletionsForQuery( query )
|
||||||
|
py results = GetCompletions( vim.eval( 'a:query' ) )
|
||||||
|
let results = pyeval( 'results' )
|
||||||
|
let s:searched_and_results_found = len( results.words ) != 0
|
||||||
|
return results
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
@ -543,24 +538,15 @@ function! youcompleteme#Complete( findstart, base )
|
|||||||
return -2
|
return -2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
py request = ycm_state.CreateCompletionRequest()
|
||||||
" TODO: make this a function-local variable instead of a script-local one
|
if !pyeval( 'request.ShouldComplete()' )
|
||||||
let s:completion_start_column = pyeval( 'base.CompletionStartColumn()' )
|
|
||||||
let s:should_use_filetype_completion =
|
|
||||||
\ pyeval( 'ycm_state.ShouldUseFiletypeCompleter(' .
|
|
||||||
\ s:completion_start_column . ')' )
|
|
||||||
|
|
||||||
if !s:should_use_filetype_completion &&
|
|
||||||
\ !pyeval( 'ycm_state.ShouldUseGeneralCompleter(' .
|
|
||||||
\ s:completion_start_column . ')' )
|
|
||||||
" for vim, -2 means not found but don't trigger an error message
|
" for vim, -2 means not found but don't trigger an error message
|
||||||
" see :h complete-functions
|
" see :h complete-functions
|
||||||
return -2
|
return -2
|
||||||
endif
|
endif
|
||||||
return s:completion_start_column
|
return pyeval( 'request.CompletionStartColumn()' )
|
||||||
else
|
else
|
||||||
return s:CompletionsForQuery( a:base, s:should_use_filetype_completion,
|
return s:CompletionsForQuery( a:base )
|
||||||
\ s:completion_start_column )
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -568,10 +554,9 @@ endfunction
|
|||||||
function! youcompleteme#OmniComplete( findstart, base )
|
function! youcompleteme#OmniComplete( findstart, base )
|
||||||
if a:findstart
|
if a:findstart
|
||||||
let s:omnifunc_mode = 1
|
let s:omnifunc_mode = 1
|
||||||
let s:completion_start_column = pyeval( 'base.CompletionStartColumn()' )
|
return pyeval( 'ycm_state.CreateCompletionRequest().CompletionStartColumn()' )
|
||||||
return s:completion_start_column
|
|
||||||
else
|
else
|
||||||
return s:CompletionsForQuery( a:base, 1, s:completion_start_column )
|
return s:CompletionsForQuery( a:base )
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -22,16 +22,64 @@ import os
|
|||||||
import vim
|
import vim
|
||||||
import ycm_core
|
import ycm_core
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
|
from ycm import base
|
||||||
from ycm.completers.all.omni_completer import OmniCompleter
|
from ycm.completers.all.omni_completer import OmniCompleter
|
||||||
from ycm.completers.general.general_completer_store import GeneralCompleterStore
|
from ycm.completers.general.general_completer_store import GeneralCompleterStore
|
||||||
|
|
||||||
|
|
||||||
|
class CompletionRequest( object ):
|
||||||
|
def __init__( self, ycm_state ):
|
||||||
|
self._completion_start_column = base.CompletionStartColumn()
|
||||||
|
self._ycm_state = ycm_state
|
||||||
|
self._do_filetype_completion = self._ycm_state.ShouldUseFiletypeCompleter(
|
||||||
|
self._completion_start_column )
|
||||||
|
self._completer = ( self._ycm_state.GetFiletypeCompleter() if
|
||||||
|
self._do_filetype_completion else
|
||||||
|
self._ycm_state.GetGeneralCompleter() )
|
||||||
|
|
||||||
|
|
||||||
|
def ShouldComplete( self ):
|
||||||
|
return ( self._do_filetype_completion or
|
||||||
|
self._ycm_state.ShouldUseGeneralCompleter(
|
||||||
|
self._completion_start_column ) )
|
||||||
|
|
||||||
|
|
||||||
|
def CompletionStartColumn( self ):
|
||||||
|
return self._completion_start_column
|
||||||
|
|
||||||
|
|
||||||
|
def Start( self, query ):
|
||||||
|
self._completer.CandidatesForQueryAsync( query,
|
||||||
|
self._completion_start_column )
|
||||||
|
|
||||||
|
def Done( self ):
|
||||||
|
return self._completer.AsyncCandidateRequestReady()
|
||||||
|
|
||||||
|
|
||||||
|
def Results( self ):
|
||||||
|
return self._completer.CandidatesFromStoredRequest()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class YouCompleteMe( object ):
|
class YouCompleteMe( object ):
|
||||||
def __init__( self, user_options ):
|
def __init__( self, user_options ):
|
||||||
self._user_options = user_options
|
self._user_options = user_options
|
||||||
self._gencomp = GeneralCompleterStore( user_options )
|
self._gencomp = GeneralCompleterStore( user_options )
|
||||||
self._omnicomp = OmniCompleter( user_options )
|
self._omnicomp = OmniCompleter( user_options )
|
||||||
self._filetype_completers = {}
|
self._filetype_completers = {}
|
||||||
|
self._current_completion_request = None
|
||||||
|
|
||||||
|
|
||||||
|
def CreateCompletionRequest( self ):
|
||||||
|
# We have to store a reference to the newly created CompletionRequest
|
||||||
|
# because VimScript can't store a reference to a Python object across
|
||||||
|
# function calls... Thus we need to keep this request somewhere.
|
||||||
|
self._current_completion_request = CompletionRequest( self )
|
||||||
|
return self._current_completion_request
|
||||||
|
|
||||||
|
|
||||||
|
def GetCurrentCompletionRequest( self ):
|
||||||
|
return self._current_completion_request
|
||||||
|
|
||||||
|
|
||||||
def GetGeneralCompleter( self ):
|
def GetGeneralCompleter( self ):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user