NativeFiletypeCompletionAvailable now a local call

It used to block on the server to get the data. Now it doesn't anymore. This
speeds up Vim startup.
This commit is contained in:
Strahinja Val Markovic 2013-10-07 16:10:48 -07:00
parent c7be1f1b47
commit 5000d2e4ae
4 changed files with 18 additions and 31 deletions

View File

@ -308,8 +308,6 @@ function! s:SetCompleteFunc()
let &completefunc = 'youcompleteme#Complete' let &completefunc = 'youcompleteme#Complete'
let &l:completefunc = 'youcompleteme#Complete' let &l:completefunc = 'youcompleteme#Complete'
" TODO: This makes startup slower because it blocks on the server. Explore
" other options.
if pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' ) if pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' )
let &omnifunc = 'youcompleteme#OmniComplete' let &omnifunc = 'youcompleteme#OmniComplete'
let &l:omnifunc = 'youcompleteme#OmniComplete' let &l:omnifunc = 'youcompleteme#OmniComplete'

View File

@ -19,6 +19,7 @@
from collections import defaultdict from collections import defaultdict
from copy import deepcopy from copy import deepcopy
import os
DEFAULT_FILETYPE_TRIGGERS = { DEFAULT_FILETYPE_TRIGGERS = {
'c' : ['->', '.'], 'c' : ['->', '.'],
@ -63,3 +64,15 @@ def TriggersForFiletype( user_triggers ):
return _FiletypeDictUnion( default_triggers, dict( user_triggers ) ) return _FiletypeDictUnion( default_triggers, dict( user_triggers ) )
def _PathToCompletersFolder():
dir_of_current_script = os.path.dirname( os.path.abspath( __file__ ) )
return os.path.join( dir_of_current_script )
def PathToFiletypeCompleterPluginLoader( filetype ):
return os.path.join( _PathToCompletersFolder(), filetype, 'hook.py' )
def FiletypeCompleterExistsForFiletype( filetype ):
return os.path.exists( PathToFiletypeCompleterPluginLoader( filetype ) )

View File

@ -22,6 +22,7 @@ import os
from ycm import extra_conf_store from ycm import extra_conf_store
from ycm.utils import ForceSemanticCompletion from ycm.utils import ForceSemanticCompletion
from ycm.completers.general.general_completer_store import GeneralCompleterStore from ycm.completers.general.general_completer_store import GeneralCompleterStore
from ycm.completers.completer_utils import PathToFiletypeCompleterPluginLoader
class ServerState( object ): class ServerState( object ):
@ -52,8 +53,7 @@ class ServerState( object ):
except KeyError: except KeyError:
pass pass
module_path = _PathToFiletypeCompleterPluginLoader( filetype ) module_path = PathToFiletypeCompleterPluginLoader( filetype )
completer = None completer = None
supported_filetypes = [ filetype ] supported_filetypes = [ filetype ]
if os.path.exists( module_path ): if os.path.exists( module_path ):
@ -114,14 +114,3 @@ class ServerState( object ):
'filetype_specific_completion_to_disable' ] 'filetype_specific_completion_to_disable' ]
return not all([ x in filetype_to_disable for x in current_filetypes ]) return not all([ x in filetype_to_disable for x in current_filetypes ])
def _PathToCompletersFolder():
dir_of_current_script = os.path.dirname( os.path.abspath( __file__ ) )
return os.path.join( dir_of_current_script, '..', 'completers' )
def _PathToFiletypeCompleterPluginLoader( filetype ):
return os.path.join( _PathToCompletersFolder(), filetype, 'hook.py' )

View File

@ -26,6 +26,7 @@ from ycm import vimsupport
from ycm import utils from ycm import utils
from ycm.completers.all.omni_completer import OmniCompleter from ycm.completers.all.omni_completer import OmniCompleter
from ycm.completers.general import syntax_parse from ycm.completers.general import syntax_parse
from ycm.completers.completer_utils import FiletypeCompleterExistsForFiletype
from ycm.client.base_request import BaseRequest, BuildRequestData from ycm.client.base_request import BaseRequest, BuildRequestData
from ycm.client.command_request import SendCommandRequest from ycm.client.command_request import SendCommandRequest
from ycm.client.completion_request import CompletionRequest from ycm.client.completion_request import CompletionRequest
@ -121,11 +122,8 @@ class YouCompleteMe( object ):
def NativeFiletypeCompletionAvailable( self ): def NativeFiletypeCompletionAvailable( self ):
try: return any( [ FiletypeCompleterExistsForFiletype( x ) for x in
return _NativeFiletypeCompletionAvailableForFile( vimsupport.CurrentFiletypes() ] )
vimsupport.GetCurrentBufferFilepath() )
except:
return False
def NativeFiletypeCompletionUsable( self ): def NativeFiletypeCompletionUsable( self ):
@ -252,14 +250,3 @@ def _AddUltiSnipsDataIfNeeded( extra_data ):
extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger, extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger,
'description': x.description 'description': x.description
} for x in rawsnips ] } for x in rawsnips ]
# 'filepath' is here only as a key for Memoize
# This can't be a nested function inside NativeFiletypeCompletionAvailable
# because then the Memoize decorator wouldn't work (nested functions are
# re-created on every call to the outer function).
@utils.Memoize
def _NativeFiletypeCompletionAvailableForFile( filepath ):
return BaseRequest.PostDataToHandler( BuildRequestData(),
'filetype_completion_available')