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:
parent
c7be1f1b47
commit
5000d2e4ae
@ -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'
|
||||
|
@ -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 ) )
|
||||
|
@ -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' )
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user