diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 69c5ce44..a0e6955d 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -40,6 +40,8 @@ function! youcompleteme#Enable() py import sys py import vim exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' + py import extra_conf_store + py extra_conf_store.CallExtraConfYcmCorePreloadIfExists() py import ycm if !pyeval( 'ycm.CompatibleWithYcmCore()') @@ -65,6 +67,7 @@ function! youcompleteme#Enable() autocmd CursorHold,CursorHoldI * call s:OnCursorHold() autocmd InsertLeave * call s:OnInsertLeave() autocmd InsertEnter * call s:OnInsertEnter() + autocmd VimLeave * call s:OnVimLeave() augroup END call s:SetUpCpoptions() @@ -190,6 +193,10 @@ function! s:SetUpCompleteopt() endif endfunction +function! s:OnVimLeave() + py extra_conf_store.CallExtraConfVimCloseIfExists() +endfunction + function! s:OnBufferVisit() if !s:AllowedToCompleteInCurrentFile() diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index b846aefc..134708cc 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -45,7 +45,10 @@ function! s:HasYcmCore() return 0 endfunction -if !s:HasYcmCore() +let g:ycm_check_if_ycm_core_present = + \ get( g:, 'ycm_check_if_ycm_core_present', 1 ) + +if g:ycm_check_if_ycm_core_present && !s:HasYcmCore() echohl WarningMsg | \ echomsg "ycm_core.[so|pyd] not detected; you need to compile YCM " . \ "before using it. Read the docs!" | diff --git a/python/extra_conf_store.py b/python/extra_conf_store.py index 3eb7aac5..ea71901a 100644 --- a/python/extra_conf_store.py +++ b/python/extra_conf_store.py @@ -25,6 +25,7 @@ import random import string import sys import vimsupport +import vim from fnmatch import fnmatch # Constants @@ -58,6 +59,23 @@ def ModuleFileForSourceFile( filename ): return _module_file_for_source_file.setdefault( filename ) +def CallExtraConfYcmCorePreloadIfExists(): + _CallExtraConfMethod( 'YcmCorePreload' ) + + +def CallExtraConfVimCloseIfExists(): + _CallExtraConfMethod( 'VimClose' ) + + +def _CallExtraConfMethod( function_name ): + vim_current_working_directory = vim.eval( 'getcwd()' ) + path_to_dummy = os.path.join( vim_current_working_directory, 'DUMMY_FILE' ) + module = ModuleForSourceFile( path_to_dummy ) + if not module or not hasattr( module, function_name ): + return + getattr( module, function_name )() + + def _Disable( module_file ): """Disables the loading of a module for the current session.""" _module_for_module_file[ module_file ] = None diff --git a/python/ycm.py b/python/ycm.py index c8d346aa..f8c68056 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -33,7 +33,6 @@ except ImportError as e: 'the docs. Full error: {1}'.format( os.path.dirname( os.path.abspath( __file__ ) ), str( e ) ) ) - from completers.all.identifier_completer import IdentifierCompleter from completers.all.omni_completer import OmniCompleter