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.
This commit is contained in:
Strahinja Val Markovic 2013-04-12 16:15:31 -07:00
parent aea154e829
commit 14b2220f01
4 changed files with 29 additions and 2 deletions

View File

@ -40,6 +40,8 @@ function! youcompleteme#Enable()
py import sys py import sys
py import vim py import vim
exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )'
py import extra_conf_store
py extra_conf_store.CallExtraConfYcmCorePreloadIfExists()
py import ycm py import ycm
if !pyeval( 'ycm.CompatibleWithYcmCore()') if !pyeval( 'ycm.CompatibleWithYcmCore()')
@ -65,6 +67,7 @@ function! youcompleteme#Enable()
autocmd CursorHold,CursorHoldI * call s:OnCursorHold() autocmd CursorHold,CursorHoldI * call s:OnCursorHold()
autocmd InsertLeave * call s:OnInsertLeave() autocmd InsertLeave * call s:OnInsertLeave()
autocmd InsertEnter * call s:OnInsertEnter() autocmd InsertEnter * call s:OnInsertEnter()
autocmd VimLeave * call s:OnVimLeave()
augroup END augroup END
call s:SetUpCpoptions() call s:SetUpCpoptions()
@ -190,6 +193,10 @@ function! s:SetUpCompleteopt()
endif endif
endfunction endfunction
function! s:OnVimLeave()
py extra_conf_store.CallExtraConfVimCloseIfExists()
endfunction
function! s:OnBufferVisit() function! s:OnBufferVisit()
if !s:AllowedToCompleteInCurrentFile() if !s:AllowedToCompleteInCurrentFile()

View File

@ -45,7 +45,10 @@ function! s:HasYcmCore()
return 0 return 0
endfunction 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 | echohl WarningMsg |
\ echomsg "ycm_core.[so|pyd] not detected; you need to compile YCM " . \ echomsg "ycm_core.[so|pyd] not detected; you need to compile YCM " .
\ "before using it. Read the docs!" | \ "before using it. Read the docs!" |

View File

@ -25,6 +25,7 @@ import random
import string import string
import sys import sys
import vimsupport import vimsupport
import vim
from fnmatch import fnmatch from fnmatch import fnmatch
# Constants # Constants
@ -58,6 +59,23 @@ def ModuleFileForSourceFile( filename ):
return _module_file_for_source_file.setdefault( 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 ): def _Disable( module_file ):
"""Disables the loading of a module for the current session.""" """Disables the loading of a module for the current session."""
_module_for_module_file[ module_file ] = None _module_for_module_file[ module_file ] = None

View File

@ -33,7 +33,6 @@ except ImportError as e:
'the docs. Full error: {1}'.format( 'the docs. Full error: {1}'.format(
os.path.dirname( os.path.abspath( __file__ ) ), str( e ) ) ) os.path.dirname( os.path.abspath( __file__ ) ), str( e ) ) )
from completers.all.identifier_completer import IdentifierCompleter from completers.all.identifier_completer import IdentifierCompleter
from completers.all.omni_completer import OmniCompleter from completers.all.omni_completer import OmniCompleter