From 78e3607b00ccbfaa244bd3867f88f051802a13cd Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Thu, 10 Oct 2013 12:55:49 -0700 Subject: [PATCH] We now only run extra conf preload for global file This changes functionality, but since this is an undocumented, non-public API, it's fine. The reason this is required is because of issue #579; if we try to run extra conf preload on non-global extra conf, we might not have the permission to load it. The global extra conf is something the user explicitly has to set so it's always fine to load that. --- python/ycm/extra_conf_store.py | 20 +++++++++----------- python/ycm/server/server_state.py | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/python/ycm/extra_conf_store.py b/python/ycm/extra_conf_store.py index 9b189153..0543a13a 100644 --- a/python/ycm/extra_conf_store.py +++ b/python/ycm/extra_conf_store.py @@ -64,26 +64,24 @@ def ModuleFileForSourceFile( filename ): return _module_file_for_source_file.setdefault( filename ) -def CallExtraConfYcmCorePreloadIfExists(): - _CallExtraConfMethod( 'YcmCorePreload' ) +def CallGlobalExtraConfYcmCorePreloadIfExists(): + _CallGlobalExtraConfMethod( 'YcmCorePreload' ) def Shutdown(): # VimClose is for the sake of backwards compatibility; it's a no-op when it # doesn't exist. - _CallExtraConfMethod( 'VimClose' ) - _CallExtraConfMethod( 'Shutdown' ) + _CallGlobalExtraConfMethod( 'VimClose' ) + _CallGlobalExtraConfMethod( 'Shutdown' ) -def _CallExtraConfMethod( function_name ): - vim_current_working_directory = os.getcwd() - path_to_dummy = os.path.join( vim_current_working_directory, 'DUMMY_FILE' ) - # The dummy file in the Vim CWD ensures we find the correct extra conf file - try: - module = ModuleForSourceFile( path_to_dummy ) - except UnknownExtraConf: +def _CallGlobalExtraConfMethod( function_name ): + global_ycm_extra_conf = _GlobalYcmExtraConfFileLocation() + if not ( global_ycm_extra_conf and + os.path.exists( global_ycm_extra_conf ) ): return + module = Load( global_ycm_extra_conf, force = True ) if not module or not hasattr( module, function_name ): return getattr( module, function_name )() diff --git a/python/ycm/server/server_state.py b/python/ycm/server/server_state.py index 88b75cb6..0e831d33 100644 --- a/python/ycm/server/server_state.py +++ b/python/ycm/server/server_state.py @@ -30,7 +30,7 @@ class ServerState( object ): self._user_options = user_options self._filetype_completers = {} self._gencomp = GeneralCompleterStore( self._user_options ) - extra_conf_store.CallExtraConfYcmCorePreloadIfExists() + extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists() @property