瀏覽代碼

Supporting YcmCorePreload logic

Now the user has the option of writing custom logic before ycm_core.so is
loaded. This can be used to dynamically change the location of where ycm_core.so
is loaded by prepending paths to sys.path.

Very, very few people will need this feature, but I'm one of them so there.
Strahinja Val Markovic 12 年之前
父節點
當前提交
14b2220f01
共有 4 個文件被更改,包括 29 次插入2 次删除
  1. 7 0
      autoload/youcompleteme.vim
  2. 4 1
      plugin/youcompleteme.vim
  3. 18 0
      python/extra_conf_store.py
  4. 0 1
      python/ycm.py

+ 7 - 0
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()

+ 4 - 1
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!" |

+ 18 - 0
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

+ 0 - 1
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