diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index de3bc3c9..fd6f77e7 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -308,8 +308,6 @@ function! s:SetCompleteFunc() let &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()' ) let &omnifunc = 'youcompleteme#OmniComplete' let &l:omnifunc = 'youcompleteme#OmniComplete' diff --git a/python/ycm/completers/completer_utils.py b/python/ycm/completers/completer_utils.py index 4fbd9b20..c700e690 100644 --- a/python/ycm/completers/completer_utils.py +++ b/python/ycm/completers/completer_utils.py @@ -19,6 +19,7 @@ from collections import defaultdict from copy import deepcopy +import os DEFAULT_FILETYPE_TRIGGERS = { 'c' : ['->', '.'], @@ -63,3 +64,15 @@ def TriggersForFiletype( 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 ) ) diff --git a/python/ycm/server/server_state.py b/python/ycm/server/server_state.py index 2e9bd9ff..88b75cb6 100644 --- a/python/ycm/server/server_state.py +++ b/python/ycm/server/server_state.py @@ -22,6 +22,7 @@ import os from ycm import extra_conf_store from ycm.utils import ForceSemanticCompletion from ycm.completers.general.general_completer_store import GeneralCompleterStore +from ycm.completers.completer_utils import PathToFiletypeCompleterPluginLoader class ServerState( object ): @@ -52,8 +53,7 @@ class ServerState( object ): except KeyError: pass - module_path = _PathToFiletypeCompleterPluginLoader( filetype ) - + module_path = PathToFiletypeCompleterPluginLoader( filetype ) completer = None supported_filetypes = [ filetype ] if os.path.exists( module_path ): @@ -114,14 +114,3 @@ class ServerState( object ): 'filetype_specific_completion_to_disable' ] 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' ) - - diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 3e64e1f3..4d7f67b4 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -26,6 +26,7 @@ from ycm import vimsupport from ycm import utils from ycm.completers.all.omni_completer import OmniCompleter 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.command_request import SendCommandRequest from ycm.client.completion_request import CompletionRequest @@ -121,11 +122,8 @@ class YouCompleteMe( object ): def NativeFiletypeCompletionAvailable( self ): - try: - return _NativeFiletypeCompletionAvailableForFile( - vimsupport.GetCurrentBufferFilepath() ) - except: - return False + return any( [ FiletypeCompleterExistsForFiletype( x ) for x in + vimsupport.CurrentFiletypes() ] ) def NativeFiletypeCompletionUsable( self ): @@ -252,14 +250,3 @@ def _AddUltiSnipsDataIfNeeded( extra_data ): extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger, 'description': x.description } 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') -